在windows下用mingw 进行编译报错,说解析模板参数列表报错。在linux下编译正确。
代码我已经简化:
#include <iostream>
using namespace std;
class Point{
public:
//实现setPoint函数
void setPoint(int x, int y){
xPos = x;
yPos = y;
}
//实现printPoint函数
void printPoint(){
cout<< "x = " << xPos << endl;
cout<< "y = " << yPos << endl;
}
private:
int xPos;
int yPos;
template <typename T>
inline bool add (T &test) {
if ( (test.start < 0) || (test.end < 0) ) { //报错位置
return true;
}else{
return false;
}
}
};
int main(){
Point M; //用定义好的类创建一个对象 点M
M.setPoint(10, 20); //设置 M点 的x,y值
M.printPoint(); //输出 M点 的信息
return 0;
}