P
Paul Bilnoski
Can someone explain why a call to a virtual function within a
constructor is illegal?
The class can't be instantiated because functions are abstract, so
whatever extends it implements them which means they should be
implemented when the constructor for the base is called.
Is it because the base gets constructed before the rest of the object
and the vftable doesn't exist?
I think something like this works in Java.
class AbstractBase
{
public:
AbstractBase();
virtual ~AbstractBase() { }
virtual void disable() = 0;
virtual void enable() = 0;
virtual bool enabled() = 0;
};
AbstractBase::AbstractBase()
{
disable();
}
--Paul
constructor is illegal?
The class can't be instantiated because functions are abstract, so
whatever extends it implements them which means they should be
implemented when the constructor for the base is called.
Is it because the base gets constructed before the rest of the object
and the vftable doesn't exist?
I think something like this works in Java.
class AbstractBase
{
public:
AbstractBase();
virtual ~AbstractBase() { }
virtual void disable() = 0;
virtual void enable() = 0;
virtual bool enabled() = 0;
};
AbstractBase::AbstractBase()
{
disable();
}
--Paul