高分!!!这是一个很牛逼的问题奥!!!跪求大侠赐教!
VC6.0下编译下面的代码居然报错!
代码:
template <typename A, typename B>
A Cast(const B& a)
{
return a;
}
int main()
{
double (*cast)(const int& a) = Cast<double, int>;
return 0;
}
错误:
F:\谭飞\VC_MyPro\C++\TempDemo\Main.cpp(75) : error C2440: 'initializing' : cannot convert from '' to 'double (__cdecl *)(const int &)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
TempDemo.exe - 1 error(s), 0 warning(s)
[解决办法]
函数指针赋值,vs2005华丽丽的编过。
[解决办法]
double (*cast)(const int& a) = Cast<double, int>;
函数指针cast不能通过返回A(这里为double型)的Cast来赋值。
另外,double (*cast)(const int& a) = Cast<double, int>;这么写看着不累么?(自己都很容易看晕),最好分开一个个的写吧。
[解决办法]
我用VC6想把C++模板的定义和实现分离,结果连支持的关键字都没有。
楼主用VC6玩Teamplate,小心了!
[解决办法]
template <typename A, typename B>A Cast(const B& a){ return a;}int main(){ double (*cast)(const int& a) = Cast<double, int>; return 0;}
[解决办法]
vs 2010
vs 2005
vs 2008 都可以