I have two classes in the same .cpp file:
// forward
class B;
class A {
void doSomething(B * b) {
b->add();
}
};
class B {
void add() {
...
}
};
The forward does not work, I cannot compile.
I get this error:
error: member access into incomplete type 'B'
note: forward declaration of 'B'
I'm using clang compiler (clang-500.2.79).
I don't want to use multiple files (.cpp and .hh), I'd like to code just on one .cpp.
I cannot write the class B before the class A.
Do you have any idea of how to resolve my problem ?
A::doSomething
after the definition ofclass B
. – dyp_b
, should be avoided. They can be used by the compiler/standard library in the global namespace; additionally, you should never use identifiers beginning with an underscore followed by an uppercase letter, such as_B
(also reserved). – dyp