当前位置: 代码迷 >> VC >> 请问大师,小弟我的这个类错在哪里
  详细解决方案

请问大师,小弟我的这个类错在哪里

热度:261   发布时间:2016-05-05 00:12:17.0
请教大师,我的这个类错在哪里?

我写了个类,带默认参数,但提示出错。

头文件ceshi.h
class CMath
{
private:

public:
static int x,y;
CMath();
CMath(int a,int b);

~CMath();

int add(int a=x,int b=y);
int minus(int a=x,int b=y);

};

源文件ceshi.cpp
#include "stdafx.h"  // 在MFC里调用需要添加此句
#include "ceshi.h"


CMath::CMath()
{
x=0;
y=0;
}
CMath::CMath(int a,int b)
{
x=a;
y=b;
}
CMath::~CMath()
{
}
int CMath::add(int a,int b)
{
return a+b;
}
int CMath::minus(int a,int b)
{
return a-b;
}

提示 :
unresolved external symbol "public: static int CMath::y" ([email protected]@@2HA)
unresolved external symbol "public: static int CMath::x" ([email protected]@@2HA)

------解决方案--------------------
http://zhidao.baidu.com/question/411539802.html
------解决方案--------------------
int CMath::x=0;
int CMath::y=0;
加上这个。
------解决方案--------------------
是的。我测试了。
  相关解决方案