inheriting a class from a partial specialization of a template class
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 che开发者_运维知识库ck&) 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 constructor check<t>
as if you inherited from check<t>
. Which check<>
do you want to inherit from?
I believe that what you really want do is this:
template<class t>
class childcheck:public check<t>
If t
is int*
, then childcheck<int*>
will inherit from check<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.
精彩评论