함수 템플릿에 다음과 같은 문제가 있습니다. 나는이 같은 함수 템플릿이있는 경우, 어디 T
중 하나 ClassA
또는 ClassB
될 수 있습니다비 템플릿 함수에 매개 변수로 템플릿 유형을 전달하는 방법은 무엇입니까?
template<typename T, bool flag>
void function(T& someT){
if(flag){ /*If 'flag' is true, 'someT' MUST be of type ClassA*/
nonTemplateFunction1(someT);
}
else{ /*Else 'someT' must be of type ClassB*/
nonTemplateFunction2(someT);
}
}
그리고 다른 파일에 나는
void nonTemplateFunction1(ClassA& a){...}
을 가지고 있고 또 다른 파일에 내가
이void nonTemplateFunction2(ClassB& b){...}
이제 함수 템플릿을 호출하면 컴파일시 오류가 발생합니다.
error: no matching member function for call to 'nonTemplateFunction2'
컴파일러가 예를 들어 ClassA
매개 변수로 nonTemplateFunction2
에 대한 호출을 테스트하기 때문일 것입니다. 그러나 이것은 결코 일어날 수 없다 (나는 적어도 프로그래머인데, 이것을 돌봐 준다). 내 프로그램을 컴파일하려면 어떻게해야합니까? 가능한 해결책은 무엇입니까?
편집 :보다 정확한 오류 :
./tabledata.hh:371:9: error: no matching member function for call to 'bulk_insert' bi.bulk_insert(bl, aRel_Vec[j]);
../pax/bulk_insert_pax.hh:21:8: note: candidate function not viable: no known conversion from 'value_type' (aka 'NSM_Relation') to 'PAX_Relation &' for 2nd argument void bulk_insert(const BulkLoader& aBulkLoader, PAX_Relation& aRelation);
흠, 난을 통과해야처럼 보인다 내 T를 가리키는 포인터. 가장 좋아하는 솔루션이 아니지만 작동해야합니다. –
@ N.Weber 가장 빠른 옵션이라고 생각합니다. –