C++ undefined reference
My problem is the following : I have a class A that inherits from an abstract base c开发者_运维百科lass. I override all the virtual functions from the base class, and I have a constructor like this :
A::A(B* b)
{
this->b=b;
}
In the constructor of class B , I have the following piece of code:
A* a=new A(this)
However this line of code gives the error : undefined reference to 'A::A(B*)'
I have absolutly no idea why could this be happening , so any suggestion would be greatly appreciated !
This is a linker error. You should probably link against the library defining A::A(A*)
.
you have to include the definition of A before the definition of B. You must also make a forward declaration of B to use it in A and prevent circular definitions.
class B;
class A
{
public :
A(B* b);
};
A* a=new A(this) // should work at this point
精彩评论