+ 1
Class into separate files
Turn a class into a file(name.h and name.cpp) is there a format or way to rewrite my class into seperate files? but still need them to communicate with each other https://code.sololearn.com/c1jxd9LGr3y0/?ref=app https://code.sololearn.com/c1jxd9LGr3y0/?ref=app
1 ответ
+ 6
E.g.
classname.h file (declares class and class members) :
class Classname {
Classname();
~Classname();
void classMethod();
}
*****************************
classname.cpp file (define class members) :
#include "classname.h"
Classname::Classname() {
// constructor definition
}
Classname::~Classname() {
// destructor definition
}
void Classname::classMethod() {
// method definition
}
*****************************
main.cpp file (your main program) :
#include "classname.h"
int main() {
Classname obj;
// do stuff
}