Includes
-
Two classes (declared in different headers and defined in different *.cpp files) use each other. How do I #include them in each other's headers correctly? When I use #pragma once it doesn't compile, but without it the headers get infinitely included.:-O Tnx in advance.
-
Two classes (declared in different headers and defined in different *.cpp files) use each other. How do I #include them in each other's headers correctly? When I use #pragma once it doesn't compile, but without it the headers get infinitely included.:-O Tnx in advance.
If the shared data are simple types such as char, int etc., wouldn't it be better to use a "global" header and place them there, or use
extern
. If the data are more complicated types (e.g. CEdit), my suggestion would be to just pass the desired data (e.g. CEdit's text - CString) between the two classes. -
If the shared data are simple types such as char, int etc., wouldn't it be better to use a "global" header and place them there, or use
extern
. If the data are more complicated types (e.g. CEdit), my suggestion would be to just pass the desired data (e.g. CEdit's text - CString) between the two classes.Each of the two classes must contain a pointer to the other one. I know it can be done, but how? The just need to be included.
-
Each of the two classes must contain a pointer to the other one. I know it can be done, but how? The just need to be included.
You can forward declare the pointed class in your
.h
file. For example, if classA
needs to point to classB
, do this (ina.h
):class B;
class A {
...
public:
B* m_pointerToB;
}/ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
You can forward declare the pointed class in your
.h
file. For example, if classA
needs to point to classB
, do this (ina.h
):class B;
class A {
...
public:
B* m_pointerToB;
}/ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
Tnx a lot. It does work.