This is a point that a constructor is not an initializer, but only
an constructer of the object. So, some of the libraries put
initialize() method separately at many classes. See the following
code:
//
// How to call a pure virtual method.
// Hitoshi Yamauchi 2007-12-5(Wed)
//
// bash % g++ -g 10purevirtual_is_called.cc
// bash % ./a.out
// pure virtual method called
// terminate called without an active exception
// Aborted
// (You need usually -g option to see this message.)
//
#include <iostream>
/// Base class
class Base {
public:
/// constructor
Base(){
this->use_pure_virtual_method();
}
/// A pure virtual method.
virtual void output_classname() = 0;
/// calling the pure virtual method in this method.
void use_pure_virtual_method(){
this->output_classname(); // implemented in the derived class.
}
};
/// Derived class
class Derived : public Base {
public:
/// constructor
Derived() : Base() {
// empty
}
/// implementation of the output_classname.
virtual void output_classname(){
std::cout << "I am [Derived]" << std::endl;
}
};
/// main
int main(){
Derived * p_derived = new Derived;
return 0;
}