- 论坛徽章:
- 0
|
本帖最后由 cppfans6 于 2012-10-03 23:24 编辑
- #include <iostream>
- #include <typeinfo>
- using namespace std;
- template <typename TP>
- struct COne
- {
- typedef TP one_value_type;
- };
- template <typename COne>
- struct CTwo
- {
- typedef typename COne<TP>::one_value_type two_value_type;
- };
- int main()
- {
- typedef COne <int> OneInt_type;
- typedef CTwo <OneInt_type> TwoInt_type;
- TwoInt_type::two_value_type i;
- int j;
- if (typeid(i) == typeid(j))
- cout << "Right! " <<endl;
- return;
- }
复制代码 编译提示错误:
Compiling...
test1.cpp
E:\LAB\stl\test1\test1.cpp(15) : error C2059: syntax error : '<'
E:\LAB\stl\test1\test1.cpp(16) : see reference to class template instantiation 'CTwo<COne>' being compiled
E:\LAB\stl\test1\test1.cpp(15) : error C2039: 'one_value_type' : is not a member of '`global namespace''
E:\LAB\stl\test1\test1.cpp(16) : see reference to class template instantiation 'CTwo<COne>' being compiled
E:\LAB\stl\test1\test1.cpp(15) : error C2238: unexpected token(s) preceding ';'
E:\LAB\stl\test1\test1.cpp(16) : see reference to class template instantiation 'CTwo<COne>' being compiled
E:\LAB\stl\test1\test1.cpp(15) : error C2059: syntax error : '<'
E:\LAB\stl\test1\test1.cpp(23) : see reference to class template instantiation 'CTwo<struct COne<int> >' being compiled
E:\LAB\stl\test1\test1.cpp(15) : error C2039: 'one_value_type' : is not a member of '`global namespace''
E:\LAB\stl\test1\test1.cpp(23) : see reference to class template instantiation 'CTwo<struct COne<int> >' being compiled
E:\LAB\stl\test1\test1.cpp(15) : error C2238: unexpected token(s) preceding ';'
E:\LAB\stl\test1\test1.cpp(23) : see reference to class template instantiation 'CTwo<struct COne<int> >' being compiled
E:\LAB\stl\test1\test1.cpp(23) : error C2039: 'two_value_type' : is not a member of 'CTwo<struct COne<int> >'
E:\LAB\stl\test1\test1.cpp(23) : error C2065: 'two_value_type' : undeclared identifier
E:\LAB\stl\test1\test1.cpp(23) : error C2146: syntax error : missing ';' before identifier 'i'
E:\LAB\stl\test1\test1.cpp(23) : error C2065: 'i' : undeclared identifier
E:\LAB\stl\test1\test1.cpp(27) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
test1.exe - 10 error(s), 1 warning(s) |
|