gcc/4.7을 사용하고 있으며 템플릿 함수 (또는 멤버 함수)에서 템플릿 템플릿 인수로 클래스를 인스턴스화해야합니다. 나는 코드가 실행되는 코드에서 표시된 두 줄을 주석으로 다음과 같은 오류템플릿 템플릿 코드가 작동하지 않습니다.
test.cpp: In function 'void setup(Pattern_Type&)':
test.cpp:17:34: error: type/value mismatch at argument 1 in template parameter list for 'template<template<class> class C> struct A'
test.cpp:17:34: error: expected a class template, got 'typename Pattern_Type::traits'
test.cpp:17:37: error: invalid type in declaration before ';' token
test.cpp:18:5: error: request for member 'b' in 'a', which is of non-class type 'int'
을받을 수 있으므로 A A는 '주'가 아닌 '설정'에서 인스턴스화 할 수 있습니다. 나는 이것이 다른 사람들에게도 흥미로울 것이라고 생각하며, 코드가 작동하지 않는 이유를 이해하게되어 정말 기쁩니다. 코드는 다음과 같습니다.
struct PT {
template <typename T>
struct traits {
int c;
};
};
template <template <typename> class C>
struct A {
typedef C<int> type;
type b;
};
template <typename Pattern_Type>
void setup(Pattern_Type &halo_exchange) {
A<typename Pattern_Type::traits> a; // Line 17: Comment this
a.b.c=10; // Comment this
}
int main() {
A<PT::traits> a;
a.b.c=10;
return 0;
}
의견이나 제안에 감사드립니다. 마우로는
MSVC10에서 컴파일됩니다. –