+ 1

How can i write c++ program in different files

what do i need to include header files & .cpp files .I really don't understand how to write a program in different files in c++ i mean what to write in them.plz explain in brief

16th Oct 2017, 3:36 PM
shobhit
shobhit - avatar
6 Answers
+ 4
every class should have an own CPP and header file
16th Oct 2017, 3:51 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 3
it is common practice to define classes in headers and then do the implementation in a cpp file. Means Zou write something like into func(int); in the header file and then you have to write the implementation in the CPP file int X::func(int b){ return b; } that's just an example
16th Oct 2017, 3:46 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 3
but if i want can i write classes in different files without header files?
16th Oct 2017, 3:49 PM
shobhit
shobhit - avatar
+ 3
but you can write of course everything directly in a cpp file, it's just not very good practice
16th Oct 2017, 3:51 PM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar
+ 3
and don't forget about the main file to test it all (you have to include all the headers)
17th Oct 2017, 6:57 AM
‎ɐısıօլɐ
‎ɐısıօլɐ - avatar