나는 임시 기본 클래스 검사와 파생 클래스 childcheck을 가지고 있습니다. 기본 클래스도 부분적으로 특수화되어 있지만 클래스 검사의 부분 전문화가 아닌 일반 템플릿 클래스에서 childcheck 클래스를 상속합니다. 난 파생 된 클래스의 초기화 목록에서 기본 클래스의 생성자를 호출 할 때, 컴파일러 나 그래서 여기 코드
템플릿 및 상속 문제!
#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");
}
는, 클래스의 검사 부분 특수화 다음 컴파일러 에러를 범하지 제거 지금 경우 오류를 범
이 예는, 대단히 바로 감사하는) 다른 같은 템플릿과는
그리고 당신은 그냥 재미 없다는 것을 발견 ... 인터페이스 다를 전문화를위한 특별한 경우를 작성해야 –