forward-declaration

C++ friend function references

I have this situation (two classes with two different header files): b.h #include "a.h" class B { friend void B* A::create(void); private: int x; }; a.h #include "b.h" class A { public: void B* create(void); ... }; basically class A creates "B" objects. I want to give the creation function create() acce...

Declare before use in C++

I'm wondering why the declare-before-use rule of C++ doesn't hold inside a class. Look at this example: #ifdef BASE struct Base { #endif struct B; struct A { B *b; A(){ b->foo(); } }; struct B { void foo() {} }; #ifdef BASE }; #endif int main( ) { return 0; } If BASE is defined, the code ...