I have a tempated base class check and publically derived class childcheck. the base class also have a partial specializatin but i inherit the childcheck class from the general templated class( not from the partial specialization of the class check). when i call the constructor of the base class from the initialization list of the derived class, compiler gives error, now if i remove the partial specialization of class check then compiler gives no error, so here is the code
#include<iostream.h>
template<class t>
class check
{
t object;
public:
check(t element);
};
template<class t>
check<t>::check<t>(t element)
{
cout<<"base class constructor"<<endl;
}
//partial specialization
template<class t>
class check<t*>
{
int objectsize;
t* object;
public:
check(t*,int);
t* getelement()const;
~check();
};
template<typename t>
check<t*>::check<t*>(t* ptr,int size)
{
cout<<"\n partial specialization constructor";
}
//derived class
template< class t>
class childcheck:public check<t>
{
t chobject;
public:
childcheck(t);
t getobject()const;
};
template<class t>
childcheck<t>::childcheck(t element):check<t>(element+1)
{
cout<<"derived class constructro"<<endl;
}
//and this is the main function
main()
{
int* ptr;
int x=2;
ptr=&x;
childcheck<int*> object(ptr);
system("pause");
}
The
check<t*>::check(t*,int);c’tor takes two parameters, but you are calling it ascheck<t>(element+1)from the derived class initialization list (with t==int*, so the partial specialization is instanced).