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

Discussion in 'C++' started by Daniel Heiserer, Aug 1, 2003.

  1. 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
    Daniel Heiserer, Aug 1, 2003
    #1
    1. Advertising

  2. Daniel Heiserer

    Artie Gold Guest

    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
    Artie Gold, Aug 1, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Quansheng Liang
    Replies:
    2
    Views:
    561
    Quansheng Liang
    May 25, 2004
  2. bp
    Replies:
    3
    Views:
    20,719
    Rolf Magnus
    Aug 20, 2004
  3. alessandro
    Replies:
    9
    Views:
    6,056
    John Harrison
    Sep 14, 2004
  4. Karl Ebener

    Undefined reference to vtable

    Karl Ebener, Nov 19, 2004, in forum: C++
    Replies:
    6
    Views:
    49,480
    Karl Ebener
    Nov 19, 2004
  5. Replies:
    1
    Views:
    657
    Jules
    Aug 18, 2005
Loading...

Share This Page