undefined reference to `vtable for Tuner' ??????

Discussion in 'C++' started by alessandro, Sep 13, 2004.

  1. alessandro

    alessandro Guest

    Compiling my current project I received the following error:
    [Linker error] undefined reference to `vtable for Tuner'
    The only two things I know are that the error occours when trying to invoke
    the constructor of a class and that concerns virtual functions.
    What does it mean?
     
    alessandro, Sep 13, 2004
    #1
    1. Advertising

  2. "alessandro" <> wrote in message
    news:Yph1d.245433$...
    > Compiling my current project I received the following error:
    > [Linker error] undefined reference to `vtable for Tuner'
    > The only two things I know are that the error occours when trying to

    invoke
    > the constructor of a class and that concerns virtual functions.
    > What does it mean?
    >


    Does Tuner or its bases have any virtual functions? Have you provided
    definitions for them? It's worth trying a total rebuild for this sort of
    problem.

    John
     
    John Harrison, Sep 13, 2004
    #2
    1. Advertising

  3. alessandro

    alessandro Guest

    that's the definition of Tuner and it's base class:

    class Tuner:Module
    {
    protected:
    SDL_Surface* display; //Main lcd-like display

    public:

    static const unsigned int type = MODULE_NONE; //Holds a code that
    specifies the module

    Tuner(Sound* s, Graphic* g, Global* gl);
    ~Tuner();

    virtual void Begin();
    /*The following methods are called whenever an input event must be
    notified
    to the module instance.*/

    virtual void MouseUp(Point* p);
    virtual void MouseMove(Point* p)
    {
    mousepos.x = p->x;
    mousepos.y = p->y;
    }
    };


    class Module
    {
    protected:
    bool running; //This thread is running
    bool pause; //This thread is in pause

    Sound* sound; //Global sound data
    Graphic* graphic; //Global graphic data
    Global* global; //Global variables

    Point mousepos; //Position of the mouse

    SDL_Surface* icon;

    public:

    static const unsigned int type = MODULE_NONE; //Holds a code that
    specifies the module

    Module(Sound* s, Graphic* g, Global* gl, char* iconname);

    //~Module()

    virtual void Begin();
    SDL_Surface* GetIcon() { return icon; }

    /*The following methods are called whenever an input event must be
    notified
    to the module instance.*/

    virtual void MouseUp(Point* p) {};
    virtual void MouseMove(Point* p)
    {
    mousepos.x = p->x;
    mousepos.y = p->y;
    }
    };
     
    alessandro, Sep 13, 2004
    #3
  4. "alessandro" <> wrote in message
    news:IIh1d.245584$...
    > that's the definition of Tuner and it's base class:
    >
    > class Tuner:Module
    > {
    > protected:
    > SDL_Surface* display; //Main lcd-like display
    >
    > public:
    >
    > static const unsigned int type = MODULE_NONE; //Holds a code that
    > specifies the module
    >
    > Tuner(Sound* s, Graphic* g, Global* gl);
    > ~Tuner();
    >
    > virtual void Begin();
    > /*The following methods are called whenever an input event must be
    > notified
    > to the module instance.*/
    >
    > virtual void MouseUp(Point* p);
    > virtual void MouseMove(Point* p)
    > {
    > mousepos.x = p->x;
    > mousepos.y = p->y;
    > }
    > };
    >
    >
    > class Module
    > {
    > protected:
    > bool running; //This thread is running
    > bool pause; //This thread is in pause
    >
    > Sound* sound; //Global sound data
    > Graphic* graphic; //Global graphic data
    > Global* global; //Global variables
    >
    > Point mousepos; //Position of the mouse
    >
    > SDL_Surface* icon;
    >
    > public:
    >
    > static const unsigned int type = MODULE_NONE; //Holds a code that
    > specifies the module
    >
    > Module(Sound* s, Graphic* g, Global* gl, char* iconname);
    >
    > //~Module()
    >
    > virtual void Begin();
    > SDL_Surface* GetIcon() { return icon; }
    >
    > /*The following methods are called whenever an input event must be
    > notified
    > to the module instance.*/
    >
    > virtual void MouseUp(Point* p) {};
    > virtual void MouseMove(Point* p)
    > {
    > mousepos.x = p->x;
    > mousepos.y = p->y;
    > }
    > };
    >


    Have you provided definitions for Tuner::Begin(), Tuner::MouseUp() and
    Module::Begin() ? Every non-pure virtual function must always be defined
    even if you don't call it.

    john
     
    John Harrison, Sep 13, 2004
    #4
  5. alessandro

    alessandro Guest

    Yes...provided a definition for every non-pure virtual function. Them are
    simply
    funcname()
    {
    }

    but that should be enaught. However these errors occour again. Note that
    these are linker errors, all in the Tuner.o file (that is, the error occours
    in the derived class).
     
    alessandro, Sep 13, 2004
    #5
  6. "alessandro" <> wrote in message
    news:Hfi1d.245823$...
    > Yes...provided a definition for every non-pure virtual function. Them are
    > simply
    > funcname()
    > {
    > }
    >
    > but that should be enaught. However these errors occour again. Note that
    > these are linker errors, all in the Tuner.o file (that is, the error

    occours
    > in the derived class).
    >


    Well I'm not sure then. Plenty of people have had this error before

    http://groups.google.co.uk/groups?i...sourceid=deskbar&q=vtable undefined reference

    Commonest reason seems to be failing to define a virtual function, but have
    a look for yourself.

    john
     
    John Harrison, Sep 13, 2004
    #6
  7. "alessandro" <> wrote in message
    news:Hfi1d.245823$...
    > Yes...provided a definition for every non-pure virtual function. Them are
    > simply
    > funcname()
    > {
    > }
    >
    > but that should be enaught. However these errors occour again. Note that
    > these are linker errors, all in the Tuner.o file (that is, the error

    occours
    > in the derived class).
    >

    Are they in form funcname() or classname::funcname() ?

    Regards,
    Slava
     
    Vyacheslav Kononenko, Sep 13, 2004
    #7
  8. alessandro

    alessandro Guest

    They are in form classname::funcname(). Now I'll install the latest mingw:
    throught google I discovered that this is a pretty common error (but nobody
    seems to be able to provide a solution or a workaround). Someone tells that
    this error is given by a recent versione of gcc but not from the previous
    ones, so I hope that using the newer available will fix the problem. Thank
    yopu for the help
     
    alessandro, Sep 14, 2004
    #8
  9. alessandro

    Howard Guest

    "alessandro" <> wrote in message
    news:IIh1d.245584$...
    > that's the definition of Tuner and it's base class:
    >
    > class Tuner:Module


    Is this legal? I thought you had to specifiy the inheritance model also
    (e.g., ": public Module)?

    Also, is there a forward declaration of Module, or is this order you've
    shown just for the purposes of posting here? As shown here, Tuner doesn't
    yet know what Module is!

    > {
    > protected:
    > SDL_Surface* display; //Main lcd-like display
    >
    > public:
    >
    > static const unsigned int type = MODULE_NONE; //Holds a code that
    > specifies the module
    >
    > Tuner(Sound* s, Graphic* g, Global* gl);
    > ~Tuner();
    >
    > virtual void Begin();
    > /*The following methods are called whenever an input event must be
    > notified
    > to the module instance.*/
    >
    > virtual void MouseUp(Point* p);
    > virtual void MouseMove(Point* p)
    > {
    > mousepos.x = p->x;
    > mousepos.y = p->y;
    > }
    > };
    >
    >
    > class Module
    > {
    > protected:
    > bool running; //This thread is running
    > bool pause; //This thread is in pause
    >
    > Sound* sound; //Global sound data
    > Graphic* graphic; //Global graphic data
    > Global* global; //Global variables
    >
    > Point mousepos; //Position of the mouse
    >
    > SDL_Surface* icon;
    >
    > public:
    >
    > static const unsigned int type = MODULE_NONE; //Holds a code that
    > specifies the module
    >
    > Module(Sound* s, Graphic* g, Global* gl, char* iconname);
    >
    > //~Module()
    >
    > virtual void Begin();
    > SDL_Surface* GetIcon() { return icon; }
    >
    > /*The following methods are called whenever an input event must be
    > notified
    > to the module instance.*/
    >
    > virtual void MouseUp(Point* p) {};
    > virtual void MouseMove(Point* p)
    > {
    > mousepos.x = p->x;
    > mousepos.y = p->y;
    > }
    > };
    >


    Most likely you haven't defined a function that is declared somewhere. How
    about the destructor for Tuner...is it defined anywhere? I see you've
    commented out the destructor declaration for Module. Did you mean to also
    comment out Tuner's destructor declaration?

    (By the way, if you're ever going to use a Module* pointer to instantiate a
    Tuner object, then you should make the Module destructor virtual.)

    -Howard
     
    Howard, Sep 14, 2004
    #9
  10. "Howard" <> wrote in message
    news:f5F1d.590129$...
    >
    > "alessandro" <> wrote in message
    > news:IIh1d.245584$...
    > > that's the definition of Tuner and it's base class:
    > >
    > > class Tuner:Module

    >
    > Is this legal? I thought you had to specify the inheritance model also
    > (e.g., ": public Module)?



    It's legal. Default is private inheritance for classes and public
    inheritance for structs.

    john
     
    John Harrison, Sep 14, 2004
    #10
    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. Daniel Heiserer
    Replies:
    1
    Views:
    2,912
    Artie Gold
    Aug 1, 2003
  2. Quansheng Liang
    Replies:
    2
    Views:
    565
    Quansheng Liang
    May 25, 2004
  3. bp
    Replies:
    3
    Views:
    20,722
    Rolf Magnus
    Aug 20, 2004
  4. Karl Ebener

    Undefined reference to vtable

    Karl Ebener, Nov 19, 2004, in forum: C++
    Replies:
    6
    Views:
    49,489
    Karl Ebener
    Nov 19, 2004
  5. jimjim
    Replies:
    9
    Views:
    732
    jimjim
    Aug 12, 2005
Loading...

Share This Page