Should all structs and classes be declared in the header file? If I declare a struct/class in a source file, what do I need to put in the header file so that it can be used in other files? Also, are there any resources that show some standard practices of C++ out there?
Share
Should all structs and classes be declared in the header file?
Yes. EDIT: But their implementations should be in cpp files. Sometimes users coming from C# or Java don’t realize that the implementation in C++ can be completely separate from the class declaration.
If I declare a struct/class in a source file, what do I need to put in the header file so that it can be used in other files?
You can’t. The compiler needs the full declaration of a class available in any translation unit that uses that class.
Also, are there any resources that show some standard practices of C++ out there?
You could just download source for any number of open source applications to see. Though the only completely consistent thing you’re likely to see is use of header guards, and keeping all declarations in header files.