//constructorofclassderivedfromtemplateclass.cpp:Defines the entry point for the console
Application.
#include "stdafx.h" template <class t> Class A {public:a () {} A (T c) {} A (a &a) {} ~a () {
} A &operator= (a &a) {return *this;
}
}; Template <class t> class b:public a<t> {public:b ()//default constructor will invoke the default constructor {} B (T c) of the template base class: A (c)//non-default constructor does not Calls the Non-default constructor of the template base class, {//Therefore, for a non-default constructor of the template base class. You should apply an initialization parameter list in a derived class to explicitly call the Non-default constructor of the template base class}//b (b &b): A (b)//copy constructor will overload the copy constructor of the template base class//{ So if you need a copy constructor for the template base class, you can define a copy constructor in a derived class,//}//, or you can also apply an initialization parameter list in a derived class to explicitly call the copy constructor of the template base class ~b ()//destructors will invoke the destructor of the template base class {}//b &oper
Ator= (B &b) The overloaded assignment operator//{//overloaded assignment operators for template base classes, so if you want overloaded assignment operators for template base classes, you should not define overloaded assignment operators//return *this in a derived class;
//}
};
int _tmain (int argc, _tchar* argv[]) {b<int> B, C;
b = C;
B<int> d (1);
B<int> e (c);
return 0; }
Derived classes default constructor constructors for template base classes non-default constructor copy constructor overload assignment operator
//Implicit call Yes Yes no no
//can manually call Yes No Yes no
//inheritance no no No Yes Yes
//Overload No no no Yes Yes
Remark: Derived classes are implicitly invoked on the constructor and destructor of the template base class, not inherited or overloaded. This is reflected in the invocation of both the constructor and the destructor of the derived class and the template base class when constructing and destructors.
// derived classes do not inherit a Non-default constructor on a template base class, so there is no need to discuss overloading a non-default constructor, but a derived class can manually explicitly call a Non-default constructor on a template base class.
MEM: Derived classes on template base classes, default constructors and destructors are implicitly called
// derived classes to the template base class, and only all constructors can explicitly call
// derived classes on the template base class in the initialization parameter list, Copy constructors and overloaded assignment operators can be inherited and overloaded