Example:
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);
}
};
Make it C#-like.
Don’t include the header, re-declare the class in the CPP but with method-bodies.
When file include the header then he gets the extern fields\methods and etc from CPP.
It’s legal? I can’t predict problems from it. There is?
This falls into the realm of the One Definition Rule. In particular, a requirement that is put on multiple definitions across several TUs of a single program for the same class is:
(Paragraph 5 of 3.2 One definition rule [basic.def.odr])
So even if you ‘fixed’ the first version to declare the member functions
inlineto match the second version (where providing a definition of the members implicitly declares theminline) you would still run afoul of this rule: the function bodies are additional tokens that appear in the one but not in the other.