컴파일러에서 read1
에 대한 일치 항목을 찾지 못하는 이유는 무엇입니까? read1
과 read2
의 차이점을 볼 수 없습니다. Foo
클래스의 중첩 typedef 템플릿에 대한 제한이 있습니까?C++ 템플릿 함수 인수로 typedef 템플릿
template<typename T>
class Handle{};
class Foo{
public:
typedef Handle<Foo> Handle;
};
template<typename T>
void read1(typename T::Handle){}
template<typename T>
void read2(Handle<T>){}
int main(int argc, char** argv)
{
Foo::Handle f1;
read1(f1);
Foo::Handle f2;
read2(f2);
}
G ++ 컴파일러 출력 (G ++ 4.4.5) 먼저
g++ -c -I. main1.cpp
main1.cpp: In function ‘int main(int, char**)’:
main1.cpp:37: error: no matching function for call to ‘read1(Handle<Foo>&)’
중복 된 '내부'네임 스페이스를 제거하고 예제를 간결하게 유지하십시오. – Xeo
G ++ 4.4.5로 편집하면 코드가 깨집니다. g ++ -c main.cpp main.cpp : 8 : 오류 : 'typedef class Handle을 선언합니다. Foo :: Handle' main.cpp : 3 : 오류 : 변경 의미 '핸들에서'클래스 핸들 ' main.cpp :'int main (int, char **) '함수에서 : main.cpp : 27 : 오류 :'read1 (핸들 &) '' –