点击(此处)折叠或打开
-
class MyClass
-
{
-
private:
-
int x,y;
-
public:
-
void setValue(int x, int y);
-
void disPlay();
- };
点击(此处)折叠或打开
-
#include <iostream>
-
#include "c.h"
-
-
using namespace std;
-
-
void MyClass::setValue(int x, int y)
-
{
-
//MyClass::x = x 或者 this->x = x
-
//x = x 会出现错误!
-
MyClass::x = x;
-
MyClass::y = y;
-
}
-
-
void MyClass::disPlay()
-
{
-
cout << "x = " << x << ",y = " << y << endl;
- }
点击(此处)折叠或打开
-
#include "fun.cpp"
-
-
int main()
-
{
-
MyClass a;
-
a.setValue(1,2);
-
a.disPlay();
-
return 0;
- }