2012-01-20 4 views
0

C++ 템플릿 상속 관련 코드에서 오류를 해결할 수 없습니다.템플릿 및 상속 : "초기화 할 수 없습니다"

template <class row> 

struct tableBase 
{ 
    typedef row pkeytype; 

    int k; 
}; 


template <typename row> 
struct table:tableBase<typename row::pkeytype> 
{ 
    row r; 
}; 


struct astruct { 

    typedef int pkeytype; 
    char y; 
}; 



table<astruct> atable; 

tableBase<astruct> * u=&atable; 

오류 : table<astruct>의 부모는 두 개의 전혀 관련이없는 유형은 tableBase<int>하지 tableBase<astruct>이기 때문이다 초기화

+0

'테이블 *'에 convertable입니다하지'하지만 *'을 tableBase. –

+0

@MooingDuck : structs public public inheritance –

답변

3

tableBase<astruct>*table<astruct>*을 변환 할 수 없습니다.

여기에서 성취하려는 것을 추측 할 수 없기 때문에 나는 제안 된 해결책을 제시 할 수 없습니다.

+0

실제로 stl을 사용하여 sqltable을 시뮬레이트하고 그 사이에 끼어 들었다. 뭔가 이런 식으로 :'table3 > players; table2 <점수, 테이블 포럼 > 득점 (선수);' – user602592

0

변경

tableBase<astruct> * u=&atable; 

tableBase<astruct::pkeytype> * u=&atable; 

에 (코드에 정의 된 tableBase의 템플릿 매개 변수가 키의 형태로 초기화되어 있습니다).

편집 :

나는이 코드를 컴파일을 할 것입니다 명시해야한다. 그것에게 일을 만드는 것은 다른 문제입니다; P

0

유형이 동일한

table<astruct> atable; // This inherits from tableBase<astruct::pkeytype> 


// The template type is astruct not astruct::pkeytype 
tableBase<astruct> * u=&atable; 
관련 문제