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

A

alessandro

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?
 
J

John Harrison

alessandro said:
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
 
A

alessandro

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;
}
};
 
J

John Harrison

alessandro said:
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
 
A

alessandro

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).
 
J

John Harrison

alessandro said:
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
 
V

Vyacheslav Kononenko

alessandro said:
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
 
A

alessandro

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
 
H

Howard

alessandro said:
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
 
J

John Harrison

Howard said:
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top