Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active October 28, 2017 06:39
Show Gist options
  • Save weshouman/ae10561226a6100eb6e236243329f1ca to your computer and use it in GitHub Desktop.
Save weshouman/ae10561226a6100eb6e236243329f1ca to your computer and use it in GitHub Desktop.
some experience in compiling cpp code #study #cpp

C++ splitting

forward declaration and header inclusion

This is what happens when we forward declare without including the header file that includes the type
It sounds there are no way out of circular includes, thus comes the perks of having #ifndef, #define and #endif wrapping all our headers
For the current project, forward declaration is used in the header files to let the classes know about others' existence and later the header files are included in the cpp files
The forward declaration error means we have found a forward declared class yet the class declaration itself wasn't found

voxelmon.cpp: In member function ‘void Voxelmon::initialize_daycarestate_special()’:
voxelmon.cpp:53:23: error: invalid use of incomplete type ‘class CHILD’
   current = new CHILD();
                       ^
voxelmon.cpp:7:7: error: forward declaration of ‘class CHILDclass CHILD;
       ^

including from other directories

ensure using / not \ in mapping directories if the file wasn't found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment