473,394 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

[Linker error] undefined reference to vtable

Hi,
I'm trying to write some classes that kind of manage themselves. A
linked list, that links different types of objects. Here's the code...

object.h:
---
class Object
{
int alt;

public:
Object *next;
Object();
virtual void draw() = 0;
};

class Projectile : public Object
{
double x, y;
double vel, dir;

public:
Projectile(double,double,double,double);
void draw();
};

object.cpp
---
#include "object.h"

Object *list = NULL;

Object::Object()
{
next = list;
list = this;
printf("object constructor got called\n");
}

Projectile::Projectile(double x, double y, double vel, double dir)
: x(x), y(y), vel(vel), dir(dir)
{
printf("projectile constructor got called\n");
}

void Projectile::draw()
{
drawDisk((int)x,(int)y,4,ColorRGB(255,0,0));
}
This linker error appears 4 times,
[Linker error] undefined reference to `vtable for Object'
And I'm not sure how to fix it. Any help?

Mar 13 '06 #1
4 5848
Mark wrote:
I'm trying to write some classes that kind of manage themselves. A
linked list, that links different types of objects. Here's the
code...

object.h:
---
class Object
{
int alt;

public:
Object *next;
Object();
virtual void draw() = 0;
If you have pure virtual functions in your class, it's a good
indication that you probably need a virtual destructor, even if
it doesn't have anything to do.
};

class Projectile : public Object
{
double x, y;
double vel, dir;

public:
Projectile(double,double,double,double);
void draw();
};

object.cpp
---
#include "object.h"

Object *list = NULL;

Object::Object()
{
next = list;
list = this;
printf("object constructor got called\n");
}

Projectile::Projectile(double x, double y, double vel, double dir)
x(x), y(y), vel(vel), dir(dir)

{
printf("projectile constructor got called\n");
}

void Projectile::draw()
{
drawDisk((int)x,(int)y,4,ColorRGB(255,0,0));
}
This linker error appears 4 times,
[Linker error] undefined reference to `vtable for Object'
And I'm not sure how to fix it. Any help?


You don't show how your classes are used, we can't help you. Please
read the FAQ, especially # 5.8.

V
--
Please remove capital As from my address when replying by mail
Mar 13 '06 #2
well, i hadnt used my classes yet, because i couldnt get it to compile
:p

intended usage is like so:

Object *obj = list;
while( obj != NULL )
{
obj->draw();
obj = obj->next;
}

anyway, adding
~Object();
to class Object fixed the problem. thanks!
not really sure how virtual destructors might work... but oh well. long
as it compiles and does what i ask...

Mar 13 '06 #3
Why is there a line that states:
virtual void draw() = 0;

To my knowledge this is an invalid line.
Mar 13 '06 #4
OK, I was wrong. =0 = pure virtual. I forgot about that, lol.
Mar 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Generic Usenet Account | last post by:
Don't you often wish that compiler and linker messages for templates were a little less cryptic and misleading? Consider this: I was getting this error message: undefined reference to `vtable...
1
by: Hardy | last post by:
Hi, just come into the boost world. just the first.cpp in the program_options examples, with many link error... devc++4.9.9.2, gcc 3.4.2, can I get your opinions on this problem? thank you~ ...
7
by: supachamp | last post by:
Hi everybody, I am having great problems with the following classes. I just can't figure out why I keep getting the error message: Building file: ../edge.cc Invoking: GCC C++ Compiler g++...
6
by: Neo | last post by:
I have a setup like class A { virtual void func1()=0; ..... } class B { virtual void func2()=0; .... } class C: public A, public B {
2
by: boyphp | last post by:
I'm getting the following undefined reference errors: foo_test.o(.gnu.linkonce.t._ZN7CFooD1Ev+0x18): In function `CFoo::~CFoo()': : undefined reference to `vtable for CFoo'...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
1
by: mubbashir | last post by:
I just created a program and used public inheritance. when compiling I am getting linker error of this kind. undefined reference to `Person::Person(char *)' undefined reference to...
2
Xx r3negade
by: Xx r3negade | last post by:
I am new to Qt. I created a basic form with 4 buttons: btn_DoSomething, btn_Clear, btn_About, btn_Browse. I used qmake-qt4 to generate the header file containing my form info (ui_myqtapp.h). I...
3
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.