I wanted to know how to deal with the following situation: suppose my main file needs to include a header file, let's call it "DigitRecognizer.h", which in itself includes a header file "PixelMap.h". If in my main class I want to pass a class specified in DigitRecognizer.h a class specified in PixelMap, I'll need to include PixelMap.h in main, but that causes problems because I'm including PixelMap twice (sorry if that was confusing, I don't know how else to word it!).
How do I get around this problem (besides maybe just lumping together PixelMap and DigitRecognizer into the same file)?
I may be misinterpreting the whole point of headers, but essentially I've been using them to make my projects modular, with each header file including some distinct functionality that can be independently maintained and tested. Is this correct? Also, is there any kind of comprehensive list of good C++ practices for me to look at?
All header files must prevent multiple insertion by using #pragma once, or if the compiler doesn't know what that is, #include guards.
In general, it is good if every header file of yours look like this:
1 2 3 4 5 6 7 8 9
#pragma once
//The following is the #include header guard.
#ifndef __MYHEADER_H__
#define __MYHEADER_H__
//The good stuff goes here.
#endif // __MYHEADER_H__
Personally, I haven't used header guards for some time, but it is nice to have them if you later want to know if a particular header has been included in order to do something else.