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; }
2 ответов
+ 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.
+ 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