By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniel Heiserer wrote:
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.
g++ inheritance.cc

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 `;'
~A(){;};
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
--
Artie Gold -- Austin, Texas

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.