-
empty constructors?
if i have a base class that has all of its functions declared virtual, even the constructor, then the classes that inherit from this class, how is the constructor called?
for example
Code:
class blah {
public:
virtual blah() {};
virtual void yay() {};
virtual ~blah() {};
}
class woo : public blah {
public:
woo() { blah * hello = new blah(); } //what is this actually doing?
void yay() {};
~woo() {};
}
-
Because you are dynamically allocating a new 'blah', the constructor for blah will be called.
EDIT: Which, in this case, wont do anything, because the constructor is empty.
-
Uhh... Make destructors virtual, but not constructors. There is no need for the concept of virtual constructors (the correct constructor will always be called explicity. Derived classes should, however, call their base class constructor in the initializer list (however, this is done automatically in the case of constructors that thake no arguments.
An example:
Code:
struct A {
A(int x) { }
};
struct B : public A {
B( ) : A(42) { }
};
Cheers