class B
{
class A;
//other parts of the definition of B
};
class B::A
{
//definition of A
};
class B
{
class A;
//other parts of the definition of B
};
class B::A
{
//definition of A
};
Quote:Original post by digitalfreak
I declared class A in the definition of class B in a .h file (in the public section). then I defined class A in the corresponding .cpp file.
the when I defined an object of A outside B like this B::A a, the complier says
error C2079: 'a' uses undefined class 'B::A'
struct foo{ struct bar;};struct foo::bar { /*definition*/ };
#include <memory>class foo { struct bar; std::auto_ptr<bar> b;public: foo(); //...};
#include "foo.hpp"struct foo::bar { /* def */ };foo::foo(): b(new bar()){}
Quote:Original post by snk_kid
Can some-body tell me what the name of this idiom is called again
"xx.h"class B{private: class A { void func_a (void); }; // other stuff};"xx.cpp"void B::A::func_a (void){ // code}
Quote:Original post by digitalfreak
but why member functions can be defined in a seperate source file?
Quote:Original post by FrunyQuote:Original post by snk_kid
Can some-body tell me what the name of this idiom is called again
Pimpl idiom, or Bridge Pattern, depending on who you're talking to.
Quote:Original post by digitalfreak
Mmm, I guess it's like snk_kid said.
but why member functions can be defined in a seperate source file?
class A { public: class B; void some_func(B *);};
class A::B { public: void some_func(void);};void A::some_func(A::B * a_b) { a_b->some_func();}void A::B::some_func(void) {}