Hi,
I have always been a little confused about inline/non-inline virtual functions and got a little more confused when I read this in a book:
According to the book the code below will fail to link on many systems(it gave no errors on mine, g++ 4.4.1). The explanation is "Even though no Base or Derived objects are created the example will fail to link on many systems. The reason is that the only virtual function in class Derived is inline (synthesized dtor), so the compiler puts a static copy of Derived::~Derived() into the current source file.Since this static copy of Derived::~Derived() invokes Base::~Base() the linker will need a definition of Base::~Base()"
class Base{
public:
virtual ~Base() throw();
};
class Derived: public Base{
};
int main(){}
Solution mentioned is to add a non-inline virtual function to derived class.
Can someone please explain what is happening here? I cannot understand why will this give a linker error, on some systems, with nothing being created at all. Also what is the problem with having only inline virtual functions in a class?