A::A[not-in-charge]() undefined reference to `vtable for A'

  • Thread starter Daniel Heiserer
  • Start date
D

Daniel Heiserer

Hi,

I got the following compiling/linking error, but I have no
clue what it is about.

Can anybody help me?

thanks, daniel

g++ inheritance.cc
/tmp/ccVdAhtt.o: In function `A::A[not-in-charge]()':
/tmp/ccVdAhtt.o(.gnu.linkonce.t._ZN1AC2Ev+0x8): undefined reference to
`vtable for A'
/tmp/ccVdAhtt.o: In function `A::~A [not-in-charge]()':
/tmp/ccVdAhtt.o(.gnu.linkonce.t._ZN1AD2Ev+0x8): undefined reference to
`vtable for A'
/tmp/ccVdAhtt.o(.gnu.linkonce.d._ZTI1B+0x10): undefined reference to
`typeinfo for A'
collect2: ld returned 1 exit status
g++ --version
g++ (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
cat inheritance.cc
#include <map>

class A{
public:
A(){;};
~A(){;};
virtual int doit();
};
class B:A{
int b;
public:
B(){b=-1;};
B(int x){b=x;};
int doit(){return b;};
};

using namespace std;
int main(){
/*
map<int,class B> Bs;
for (int x=0;x<10;x++){
Bs[x]=B(x*x);
}
for (map<int,B>::iterator IT=Bs.begin();IT!=Bs.end();IT++){

fprintf(stdout,"Bs[%d]=%d\n",IT->first,IT->second.doit());
}
*/
class B Bs1;
Bs1=B(23);
fprintf(stdout,"Bs[%d]=%d\n",23,Bs1.doit());
return 0;
}

-- thanks, daniel
 
A

Artie Gold

Daniel said:
Hi,

I got the following compiling/linking error, but I have no
clue what it is about.

Can anybody help me?

thanks, daniel
Sure. Please see below.

First of all, TURN UP YOUR WARNINGS! (sorry for yelling ;-))
It will save you much grief in the long run.
/tmp/ccVdAhtt.o: In function `A::A[not-in-charge]()':
/tmp/ccVdAhtt.o(.gnu.linkonce.t._ZN1AC2Ev+0x8): undefined reference to
`vtable for A'
/tmp/ccVdAhtt.o: In function `A::~A [not-in-charge]()':
/tmp/ccVdAhtt.o(.gnu.linkonce.t._ZN1AD2Ev+0x8): undefined reference to
`vtable for A'
/tmp/ccVdAhtt.o(.gnu.linkonce.d._ZTI1B+0x10): undefined reference to
`typeinfo for A'
collect2: ld returned 1 exit status
g++ --version

g++ (GCC) 3.2.2
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

cat inheritance.cc

#include <map>

class A{
public:
A(){;};

Spurious trailing `;'

Spurious trailing `;'
Non-virtual destructor! (Classes from which you inherit - that have
virtual functions - need a virtual destructor.)
virtual int doit();

No implementation of this function?
};
class B:A{
int b;
public:
B(){b=-1;};
B(int x){b=x;};
int doit(){return b;};
};

using namespace std;
int main(){
/*
map<int,class B> Bs;
for (int x=0;x<10;x++){
Bs[x]=B(x*x);
}
for (map<int,B>::iterator IT=Bs.begin();IT!=Bs.end();IT++){

fprintf(stdout,"Bs[%d]=%d\n",IT->first,IT->second.doit());
}
*/
class B Bs1;
Bs1=B(23);
fprintf(stdout,"Bs[%d]=%d\n",23,Bs1.doit());
return 0;
}

-- thanks, daniel

Turning up your warnings is _always_ a good idea; compiler warnings are
usually much better (and more comprehensible) than linker errors by
themselves (as the former relate to source code).

HTH,
--ag
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top