例子:
H
class MyClass {
int x,y,z;
public:
MyClass(int,int,int);
void X();
void Y();
void Z();
};
CPP
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 获取外部字段\方法等。
合法吗?我无法从中预测问题。有?