0

Plis tell me... which lines need to be in the

1.source files. 2.header file. 3.main file #include <iostream> using namespace std; class MyClass { public: MyClass(); ~MyClass(); }; MyClass::MyClass() { cout<<"Constructor"<<endl; } MyClass::~MyClass() { cout<<"Destructor"<<endl; } int main() { MyClass obj; }

31st Aug 2017, 6:37 AM
stephen haokip
stephen haokip - avatar
2 Antworten
+ 11
Technically, all of it can exist within main.cpp. However, if you want to sort em: MyClass.h should contain your class declaration. MyClass.cpp should include MyClass.h and its corresponding class definition. main.cpp would include MyClass.h and main() definition.
31st Aug 2017, 7:34 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
main file : the main function + include of the header file header file : include of iostream, using namespace std, declaration of the class and declaration of template parts of the file source file : include of the header file and definition of none template part of the class
31st Aug 2017, 7:34 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar