Use this form for your nested inclusions:
Stuffpollection.h
#ifndef STUFFCOLLECTION_H_GUARD #define STUFFCOLLECTION_H_GUARD class Spritesheet; class Stuffcollection { public: void myfunc (Spritesheet *spritesheet); void myfuncTwo (); }; #endif
Stuffcollection.cpp
#include "Stuffcollection.h" #include "Spritesheet.h" void Stuffcollection::myfunc(Spritesheet *spritesheet) { unsigned int myvar = 5 * spritesheet->spritevar; } void Stuffcollection::myfuncTwo() {
Spritesheet.h
#ifndef SPRITESHEET_H_GUARD #define SPRITESHEET_H_GUARD class Spritesheet { public: void init(); }; #endif
Spritesheet.cpp
#include "Stuffcollection.h" #include "Spritesheet.h" void Spritesheet::init() { Stuffcollection stuffme; myvar = stuffme.myfuncTwo(); }
General rules that I adhere to:
- Don't include include from include, dude. Assume forward declarations, if possible.
- Exception: turn on the system anywhere.
- CPP has everything you need without relying on recursively H, including its files.
- Always use protective devices.
- Never use
pragma
source share