以下代碼不能用G ++ 4.5或4.6(快照)編譯。它將使用Digital Mars Compiler 8.42n進行編譯。爲什麼這個小型的C++程序不能用G ++編譯?
template <int I>
struct Foo {
template <int J>
void bar(int x) {}
};
template <int I>
void test()
{
Foo<I> a;
a.bar<8>(9);
};
int main(int argc, char *argv[]) {
test<0>();
return 0;
}
的錯誤信息是:
bugbody.cpp: In function 'void test() [with int I = 0]':
bugbody.cpp:16:11: instantiated from here
bugbody.cpp:11:3: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'
是程序有效C++?
[模板函數調用的模板類的C++模板成員函數]的可能重複(http://stackoverflow.com/questions/1840253/c-template-member-function-of-template-class-called-from-模板函數) – 2011-05-04 11:22:35
可能的重複[哪裏,爲什麼我必須把「模板」和「類型名稱」依賴名稱?](http://stackoverflow.com/questions/610245/where-and-why-do-我必須把模板和類型名稱的依賴名稱) – 2011-05-04 11:43:15