#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]