문제

템플릿 기능이 있습니다.

template<typename T>
void foo(const T& value) { bar(value); x = -1; }

일련의 유형에 대해 전문화하고 싶습니다.

template<>
void foo<char>(const char& value) { bar(value); x = 0; }
template<>
void foo<unsigned char>(const unsigned char& value) { bar(value); x = 1; }

괜찮습니다. 내가 이것을 컴파일 할 때 :

template<>
void foo<char*>(const char*& value) { bar(value); x = 2; }

오류가 발생합니다.

error C2912: explicit specialization; 'void foo(const char *&)' is not a specialization of a function template

전문화 할 수 있습니까? char* typedef'ing이없는 포인터 유형 매개 변수?

도움이 되었습니까?

해결책

확신하는. 이 시도:

template<>
void foo<char*>(char* const& value) {...}

이 때문입니다 const char* 포인터를 의미합니다 const char, const 포인터 char.

다른 팁

일반적으로 기능 템플릿 전문화를 피해야합니다. 대신 비 테일 플레이트 오버로드를 제공하면 훨씬 적은 문제가 발생합니다. 더 읽기 : 기능 템플릿을 전문화하지 않는 이유는 무엇입니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top