template <class Type>
class counter
{
public : counter(Type N=0) { data = N; }
void increment(Type D=1) { data += D; }
};
template <class Type>
class general_counter : public counter<Type>
{
public:
/* This line */
general_counter(Type N=0) : counter(N) { }
void setcounter(Type N=0) { data = N; }
}
Can we initialize the variable that is argument to a constructor, does it have any specific purposes? Why do we call the constructor of the base template class in the inherited class?
It is called that to pass argument N that is specified in the derived constructor to the base constractor that to initialize the data member data of the base class. Otherwise if the explicit call will not be specified the base class will be initialized with implicit call base( 0 ) ( because the default argument is equal to 0 ).