test.cpp:6:2: error: missing 'typename' prior to dependent type name 'C::const_iterator' C::const_iterator begin(container.begin()); ^~~~~~~~~~~~~~~~~ typename test.cpp:7:2: error: missing 'typename' prior to dependent type name 'C::const_iterator' C::const_iterator end(container.end()); ^~~~~~~~~~~~~~~~~ typename 2 errors generated.
如果你在这里使用的是class而不是typename就会报错:
1 2 3 4 5 6 7 8 9 10
test.cpp:8:11: error: elaborated type refers to a typedef class C::const_iterator begin(container.begin()); ^ test.cpp:15:2: note: in instantiation of function template specialization 'lastGreaterThanFirst<std::__1::vector<int, std::__1::allocator<int> > >' requested here lastGreaterThanFirst(vec); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:476:54: note: declared here typedef __wrap_iter<const_pointer> const_iterator; ^ 1 error generated.