#include directive :
- Use in both .h header file and implementation file
- Base classes are introduced by using include directives
forward declaration :
- Use in .h header file
- Pointer return values and method parameters can be forward declared
Sample.h file :
//include directive for base class #include "BaseItemEntity.h" //forward declaration for method parameters and return values class QString; class Item; class ItemBody : public BaseItemEntity { public: QString getItemID(); Item* getItemByName(QString&); };
Sample.cpp file :
#include "Sample.h" #include "Item.h" QString ItemBody::getItemID() { return QString(); } Item* ItemBody::getItemByName( QString& name) { Item* item = new Item(name); return item; }
There is also a useful c++ coding guide that is giving clues for header file dependencies at this link