Advertisement

programming the neat way

Started by January 31, 2004 03:59 PM
15 comments, last by Marty666 21 years, 1 month ago
quote:
Original post by owl
quote:
Original post by DerAnged
OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!


Nope. Unexpected end of file usually happen when the compiler doesn''t parse the source correctly.

What you say has a message like "Extra line missing at the end of file".

[edited by - owl on January 31, 2004 5:30:15 PM]


i stand corrected.


#pragma once  

is easier than all the #ifdef _BLAH stuff.

I'm not entirly sure what your problem is, but this may help.

Assume the following:

when you use #include ... it takes the header file, and 'copies and pastes' it into the current file.

So, if you have two files like this:

first.h:
#pragma once#include "second.h"...   


second.h:

#pragma once#include "first.h"...   


then, you get a problem.

say the first header to be loaded from a .cpp file is first.h (doesn't have to be) then it will do:

#pragma once#include "second.h"    ---->                                  #pragma once                                  #include "first.h"                                                          ---->                                                          #pragma once // fails! (first.h)                                                          <----                                        ... (rest of code for second.h)                       <----... (rest of code for first.h) 


so when the code in second.h is processed, the code in first.h hasn't be processed yet. This is the 'chicken and egg' problem.

All your errors are occuring in the .h files..

The way to solve this is to simply do what was mentioned before.

predefine the class names...

eg,


#pragma onceclass Matrix;class Quaternion{    Matrix QuatToMatrix();    ...};   


if, however, you did this:



#pragma onceclass Matrix;class Quaternion{    Matrix QuatToMatrix()    {        return Matrix(...);    }    ...};


you would get an error since the Matrix class is not yet defined, and therefor it's constructors are not known... so you can't return a Matrix(...). You can in the .cpp, since they will be defined by then.

| - My (new) little website - | - email me - |

[edited by - RipTorn on February 1, 2004 2:29:53 AM]
Advertisement
Ok, this is what I did:

All the .h files don''t contain any functions anymore. All the classes are predefined in the .h files and DON''T have their functions and operators inline, but these functions are defined. All the corresponding .cpp files contain the functions and operators.
The .h files contain all the #includes that the corresponding .cpp file is going to use, so if i do this:

// quaternion.h#pragma once#include "matrix.h"#include "vector.h"#include <math.h>class c_quat{public:	void ExtractMatrix(c_matrix &m);	void RotateVector(c_vec3 &v);...}; 


The compiler is going to know what a c_matrix and a c_vec3 is. Because I put in the ''#include''s. In the .cpp files (for example quaternion.cpp the compiler doesn''t know what a c_vec3 is anymore, allthough I do ''#include quaternion.h''?!?

I don''t get this. Maybe I should stick with one very big and ugly .h file anyways

Marty
_____ /____ /|| | || MtY | ||_____|/Marty
Instead i made a .h file with all the conversions like quattomatrix and matrixtoquat, etc. The files won''t have any problems this way.
I''m stuck with these errors:

Compiling...
model.cpp
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing '';'' before type ''void''
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ''WINGDIAPI'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
textures.cpp
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing '';'' before type ''void''
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: ''WINGDIAPI'' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

NukeM2.exe - 6 error(s), 0 warning(s)
_____ /____ /|| | || MtY | ||_____|/Marty
#include <windows.h>
Visual 6 might have a way to show includes as the build progresses. It''ll give you a tree of the include dependancies for each file. It''s handy to see what''s getting referenced.

I know VS.NET has it, at least.

I like pie.
[sub]My spoon is too big.[/sub]
Advertisement
"OH AND USUALLY! unexpected end of file MEANS THAT THERES NOT AN EXTRA EMPTY LINE AT THE END OF THE .H FILE!"
This is true. Sometimes when I don''t have a newline after #endif, I get an error stating that there was an unexpected end of file. (In Microsoft Visual C++ anyway)





/*
I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)
*/

This topic is closed to new replies.

Advertisement