Class into separate files | Sololearn: Learn to code for FREE!

+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

7/16/2018 12:19:59 AM

DerpyCoco

1 Answer

New Answer

+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 }