超级难的template问题,求高手帮忙!!
#include "stdafx.h "
class xxx
{
};
template <typename T>
struct struct1;
template <>
struct struct1 <int>
{
typedef xxxid;
};
template <typename T>
int fuction1(typename struct1 <T> ::id& id)
{
}
int main(int argc, char* argv[])
{
printf( "Hello World!\n ");
return 0;
}
报告错误如下:
Compiling...
template_test3.cpp
F:\work\vc\teck\template_test3\template_test3.cpp(18) : error C2039: 'id ' : is not a member of 'struct1 <T> '
F:\work\vc\teck\template_test3\template_test3.cpp(18) : error C2143: syntax error : missing ', ' before '& '
F:\work\vc\teck\template_test3\template_test3.cpp(18) : error C2501: 'id ' : missing storage-class or type specifiers
F:\work\vc\teck\template_test3\template_test3.cpp(18) : error C2059: syntax error : '& '
Error executing cl.exe.
template_test3.exe - 4 error(s), 0 warning(s)
[解决办法]
template <typename T>
struct struct1;
template <>
struct struct1 <int>
{
typedef xxxid;
};
说明只有int特化版本有id其它的非但没有id而且没有实现
[解决办法]
g++ 3.4.5直接编译过去,
你没实例化,所以能直接编译过去。
另外
你的编译器需要升级。
[解决办法]
你是啥编译器?
用devcpp或者vc2005编译了试一下。
[解决办法]
你用的VC6是正版的吗,非要用MS的东西,就去网上下一个visual c++ express 2005 吧