Monday, December 8, 2008

Few problems u might possibly encounter when deriving class from base class

1. undefined reference to `vtable for XXXXXXX'

vtable means virtual table, all errors about undefined reference to vtable are caused due to virtual function in class!
This error might raised due to you declare the virtual functions which are inherited from base class in derived class without implementation.

e.g.

class Base
{
public:


Base();
virtual ~Base();

virtual void foo() = 0;
};

class Dclass : Base
{
public:

Dclass();

~Dclass();


void foo();

};

Dclass::Dclass() : Base()
{}

Dclass::~Dclass()
{}

void Dclass::foo() // will cause error if not be implemented!!!
{}

e.g


if you declare some virtual functions in xxx.h file, you must implement them(those virtual functions) after ctor implementation. or it will cause undefined reference to `vtable for XXXXXX'

No comments: