H
Henning Hasemann
Hi all,
On larger projects I used the following 'technique' (well in fact its a
really simple thing):
1. Write one source-code file for each 'large' class and one
corresponding header file. (code in source-code file declaration in
header file, as usual)
2. Write a central header file which first holds forward declarations of
all classes an then includes all other header files.
3. Include the central header fillfrom all source-code files, so the
declarations of every class is available everywhere.
I think thats a usual practice (correct me, if Im wrong).
I always though, this way I whould not have to care about teh ordering
of the header-file inclusion, but when a class uses members of whose
types are other self-defined classes the forward declaration does not
seem to be enough.
Short example:
// main.h
class A;
class B;
#include "a.h"
#include "b.h"
// a.h
class A {
private:
B mSomething; // Forward declaration of B not enough here
// ...
};
The same problem arises when I try to inherit from a class which is just
forward-declared.
Can I fix this without finding out an unproblematic order of header
files and without making pointers out of every Member?
Whats the usual approach to this problem?
TIA
Henning
On larger projects I used the following 'technique' (well in fact its a
really simple thing):
1. Write one source-code file for each 'large' class and one
corresponding header file. (code in source-code file declaration in
header file, as usual)
2. Write a central header file which first holds forward declarations of
all classes an then includes all other header files.
3. Include the central header fillfrom all source-code files, so the
declarations of every class is available everywhere.
I think thats a usual practice (correct me, if Im wrong).
I always though, this way I whould not have to care about teh ordering
of the header-file inclusion, but when a class uses members of whose
types are other self-defined classes the forward declaration does not
seem to be enough.
Short example:
// main.h
class A;
class B;
#include "a.h"
#include "b.h"
// a.h
class A {
private:
B mSomething; // Forward declaration of B not enough here
// ...
};
The same problem arises when I try to inherit from a class which is just
forward-declared.
Can I fix this without finding out an unproblematic order of header
files and without making pointers out of every Member?
Whats the usual approach to this problem?
TIA
Henning