Need help on this error

N

Neo

I have the following code structure-
class A {
public:
virtual void foo_a()=0;
};

class B {
public:
virtual void foo_b()=0;
};

class AB: public A, public B {
public:
void foo_a(){...}
void foo_b(){...}
AB(){...}
};

And further I have pointers to objects of class AB in my other modules.
Now I am getting multiples of this error: "Undefined reference to VTT
for AB". I have taken care not to leave any functions undefined which
are declared in abstract classes A and B. I need help badly in
resolving this as I am new to c++.

thanks,
Neo
 
B

Bjoern Doebel

Neo said:
I have the following code structure-
class A {
public:
virtual void foo_a()=0;
};

class B {
public:
virtual void foo_b()=0;
};

class AB: public A, public B {
public:
void foo_a(){...}
void foo_b(){...}
AB(){...}
};

And further I have pointers to objects of class AB in my other modules.
Now I am getting multiples of this error: "Undefined reference to VTT
for AB". I have taken care not to leave any functions undefined which
are declared in abstract classes A and B. I need help badly in
resolving this as I am new to c++.

Compiles for me with g++-3.4 and g++-4.1.2 - perhaps it is a compiler
issue. If I run g++ with -Wall, then I'm told that virtual destructors are
missing:
bla.cc:19: warning: ‘class A’ has virtual functions but non-virtual destructor
bla.cc:24: warning: ‘class B’ has virtual functions but non-virtual destructor
bla.cc:29: warning: ‘class AB’ has virtual functions but non-virtual destructor

Bjoern
 
O

Ondra Holub

Neo napsal:
I have the following code structure-
class A {
public:
virtual void foo_a()=0;
};

class B {
public:
virtual void foo_b()=0;
};

class AB: public A, public B {
public:
void foo_a(){...}
void foo_b(){...}
AB(){...}
};

And further I have pointers to objects of class AB in my other modules.
Now I am getting multiples of this error: "Undefined reference to VTT
for AB". I have taken care not to leave any functions undefined which
are declared in abstract classes A and B. I need help badly in
resolving this as I am new to c++.

thanks,
Neo

You should post minimalized, but complete code, which does not compile.
You should define virtual destructor for A and B, but I do not think it
is problem here.
 
G

Grizlyk

Neo said:
Now I am getting multiples of this error: "Undefined reference to VTT
for AB". I have taken care not to leave any functions undefined which
are declared in abstract classes A and B. I need help badly in
resolving this as I am new to c++.

It is maybe link time error. Maybe you do not include no one object
file with compiled class declaration. For example (if I do not do
mistake) the error can occure due to improper use of #pragma
interface/#pragma implementation for gxx compiler.
 
N

Neo

Ondra said:
Neo napsal:

You should post minimalized, but complete code, which does not compile.
You should define virtual destructor for A and B, but I do not think it
is problem here.

I am sorry I dont really know what the hell is happening. I also cant
post the complete code as it requires other libraries which are
numerous. But If it will help I noticed that only when I instatiate
objects of class AB in the upper module does this error come up else it
goes fine. I am using gcc 3.4.4 compiler. Or if I can get the
exhaustive list of conditions for which I get such an error I could
check for each of them in turn.

thanks,
neo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top