Class declaration into a header?
Hello, I've seen the following code in a EnemyManager.h file:
I don't understand what this does
mean. Because if you just do a
it works perfectly too.
What am I missing here?.(I'm also new to C++)
If you include a header file, you copy everything in that file at the position where the include statement is. Just writing
Means you are declaring the class, so you are telling the compiler „this class does exists“ and you would use this if you only need the class as a datatype in the file, because that way you are not including the entire head file.
answered Feb 13 '18 at 12:14 PM
This is called forward declaration, you declare incomplete class for type to work in header file, later it is properly declared in different include in cpp file (note that true function of #include is pasting content of the file to another file and fact that header files alone are never compiled on there own they are used in compilation of cpp files) if type is really used in cpp file, otherwise you will get use of incomplete type error. This is to avoid circular dependency in header files which may cause issues, if possible you should avoid including header file other then one containing base class of class you declaring, and forward declaration is one of methods to avoid that.
You can read about it here:
Follow this question
Once you sign in you will be able to subscribe for any updates here