Hello.
Can anyone point me to a tutorial on how to properly organize header files?
What I have (this time, I really can't post the code itself) is an MFC document class that contains a vector of classes that have an instance of a pointer to a base class (defined in another header).
This base class is polymorphic with (currently) two derived classes. These classes need to have data type information from three header files that contain structs, macros, and externs that will apply to most of the different classes. However, I do not mean that the same structs and definitions are reused by the different derived classes, just that these headers have a huge number of typedefs that are not strongly related in code, but associate logically.
I have already used #ifndef,#define, and #endif preprocessor commands to surround each header, but there are still many "LNK2005, already defined in *.obj" errors and "LNK2001, unresolved external symbol" errors.
Here's what I mean, in pseudo code.
The files:
MFCDoc.h, .cpp:
BaseClass.h
Derived1.h, .cpp
Derived2.h, .cpp
Define1.h, Define2.h, Define3.h: The globals, typedef structs, macros and #defines.
//BaseClass.h
#ifndef BASECLASS
#define BASECLASS
#include "Define1.h"
#include "Define2.h"
#include "Define3.h"
#endif
//Derived1.h
#ifndef DERONE
#define DERONE
#include "BaseClass.h"
#endif
//Derived1.cpp
#include "Derived1.h"
//Derived2.h
#ifndef DERTWO
#define DERTWO
#include "BaseClass.h"
#endif
//Derived2.cpp
#include "Derived2.h"
//MFCDoc.h
#ifndef MFC_DOC
#include MFC_DOC
#include "BaseClass.h"
#include "Derived1.h"
#include "Derived2.h"
//Class1: Data class with pointer to baseclass type
//Class2: Document class, with vector of Class1 instances.
#endif
//MFCDoc.cpp
#include "MFCDoc.h"
Is this appropriate? It's been suggested that I try to leave two of the definition headers alone, so if there's an arrangement where I can have all those headers available to all the files without redefintion errors, I'd like to know how to do that.