关于模板元编程的困惑
#include <iostream>
using namespace std;
template<int Base, int Exponent>
struct XY
{
public:
enum{ result_ = Base * XY<Base, Exponent-1>::result_};
};
template<int Base>
struct XY<Base, 0>
{
public:
enum { result_ = 1 };
};
int main()
{
//std::cout << "X^Y<5, 4>::result_ = " << XY<5,4>::result_;
return true;
}
为什么这个程序在VC6.0上编译,会出现错误。
错误信息提示为:
error C2989: 'XY<Base,0>' : template class has already been defined as a non-template class
error C2988: unrecognizable template declaration/definition
[解决办法]
倒!楼主竟然试图在VC6这种垃圾货上玩模板元编程。
[解决办法]
你写的代码用到了很多新的语法,VC6所带的编译器是不支持的
[解决办法]
VC6自带的编译器不支持模板部分特化
[解决办法]
其实我是来打酱油的哦~
[解决办法]
vc6 太老了
换个vs2005或者vs2010吧
或者gcc