I have a templated class named check and its partial specialization, now i am publically inheriting a class named childcheck from the partial specialization of the class check. but compiler gives following error message
no matching function for call to `check::check()’
candidates are: check::check(const check&)
check::check(t*) [with t = int*]
look at the code and explain the reason please
#include<iostream.h>
template<class t>
class check
{
t object;
public:
check(t);
};
//defining the constructor
template<class t>
check<t>::check<t>(t element)
{
cout<<"general templated class constructor"<<endl;
}
//partial specialization
template<class t>
class check<t*>
{
t* object;
public:
check(t*);
};
template<class t>
check<t*>::check<t*>(t* element)
{
cout<<"partial specialization constructor"<<endl;
}
//childcheck class which is derived from the partial specialization
template<class t>
class childcheck:public check<t*>//inheriting from the partial specialization
{
t object;
public:
childcheck(t);
};
template<class t>
childcheck<t>::childcheck<t>(t element):check<t>(element)
{
cout<<"child class constructor"<<endl;
}
main()
{
int x=2;
int*ptr=&x;
childcheck<int*>object(ptr);
cout<<endl;
system("pause");
}
You inherit from
check<t*>yet call a base class constructorcheck<t>as if you inherited fromcheck<t>. Whichcheck<>do you want to inherit from?I believe that what you really want do is this:
If
tisint*, thenchildcheck<int*>will inherit fromcheck<int*>which is fine. The rest of your code can remain the way it is in the original question.Read about Template Partial Specialization at cprogramming.com, it explains
your previous question.