tags:

views:

153

answers:

2

Hi ,

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 !

+3  A: 

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

honk
Could you be more specific, of what I have to do ?
That defends on your environment, i.e. what compiler and/or linker you are using.
honk
I use NetBeans 6.8 in UBuntu
I have no idea about netbeans, but it probably uses `g++` at some point. There has to be some menu to set the linker options. See if you can add `-lLIBRARY_WITH_A` to the linker flags. If `A` is defined in a directory not under something like `/usr/lib` you also need to pass that to the linker with `-LPATH_TO_LIBRARY_WITH_A` (only the directory of the library).
honk
Sorry, `-lLIBRARY_WITH_A` should of course be without the `lib` and `.so.X.Y.Z` parts of the filename.
honk
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
Seb
I've included the header of A in the class B, if that's what you means
Did you implement all abstract members of the base class in A ?
Seb