I don't see anything horribly wrong, except that you aren't using public inheritance. (You should generally stick to public inheritance unless you know what you are doing...)
#include <iostream>
usingnamespace std;
template<typename T>class clsTemplate
{
public:
T value;
clsTemplate(T i)
{
this->value = i;
}
void test()
{
cout << value << endl;
}
};
class clsChild : public clsTemplate<char>
{
public:
clsChild(/* no parameters */): clsTemplate<char>( 0 ) // default char is NUL
{
;
}
clsChild(char c): clsTemplate<char>( c )
{
;
}
void test2()
{
test();
}
};
int main()
{
clsTemplate <int> a( 42 );
clsChild b( 'A' );
a.test(); // should print "42"
b.test(); // should print "A"
b.test2(); // should print "A"
return 0;
}
When you are constructing descendent classes, it is generally a good idea to initialize the ancestor class in the constructor's initializer list, even if that is the only thing you do:
1 2 3
clsChild():
clsTemplate <char> ( ' ' ) // default char is SPACE
{ }