klaus johan
klaus johan

Reputation: 4400

C++ undefined reference

My problem is the following : I have a class A that inherits from an abstract base class. 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 !

Upvotes: 0

Views: 378

Answers (2)

Seb
Seb

Reputation: 2715

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

Upvotes: 0

Benjamin Bannier
Benjamin Bannier

Reputation: 58556

This is a linker error. You should probably link against the library defining A::A(A*).

Upvotes: 3

Related Questions