Example:
H
class MyClass {
int x,y,z;
public:
MyClass(int,int,int);
void X();
void Y();
void Z();
};
C++
class MyClass {
int x,y,z;
public:
MyClass(int x,int y,int z) {
this->x=x;
this->y=y;
this->z=z;
}
void X() {
printf("x = %d;\n",x);
}
void Y() {
printf("y = %d;\n",y);
}
void Z() {
printf("z = %d;\n",z);
}
};
让它看起来像C#。 不要包含头文件,在CPP文件中重新声明类但带有方法体。 当文件包括头文件时,它会从CPP获取extern字段、方法等。
这合法吗?我不能预测其中的问题。存在问题吗?
this->x
而不是像x(x)
这样初始化? - tadmandrugs.sell(plenty)
? - Mat