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? 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
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...
Why is there a line that states:
virtual void draw() = 0;
To my knowledge this is an invalid line.
OK, I was wrong. =0 = pure virtual. I forgot about that, lol. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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~
...
|
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++...
|
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 {
|
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'...
|
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...
|
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...
|
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...
|
by: Rahul |
last post by:
Hi Everyone,
I have the following polymorphic classes,
class Shape
{
public : virtual void draw()
{
}
virtual void sample();
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |