Click to See Complete Forum and Search --> : Can't include Document header file in new class!


June 9th, 1999, 11:06 AM
Hello,

I'm writing an SDI and I've written a subclass called CDemoDriver. I need to instantiate this in the DOC class, and the CDemoDriver also needs to reference the DOC class. So it's a two way relationship. My problem is that when I try to include the other classes' header file in each of the classes, it doens't work. For example I need to include DemoDriver.h in the Document class and vice-versa. It just acts as if the header file was not included. I have a feeling it's a simple problem but it's been driving me crazy!!

Thanks in advance!
Rich Taylor

Wayne Fuller
June 9th, 1999, 12:07 PM
I do not see why the CDemoDriver needs to know about the Doc class, but who knows you are writing the code. Make sure you only have included the header
file one time with your CDemoDriver class by putting the following line at the top of DemoDriver.h
// This is at the top
#ifndef __DEMO_DRIVER_HEADER_FILE
#define __DEMO_DRIVER_HEADER_FILE
...
// This is at the bottom
#endif



If you already have done this, send me exactly how you are using the #include directives. You can take out your sensitive code. The problem looks
like you are including header files too many times. This happens quite easy when you start to include header files in your header files.

Wayne

John Holifield
June 9th, 1999, 01:59 PM
You can run the OneTimeInclude macro on your header file(s) to automatically add code similar to what Wayne is showing you. As a matter of practice, you should do this for all your header files.

You might also try *Not* using #include(s) for other classes in your header files. Use a forward declaration instead. In other words, in your DemoDriver.h file instead of:

#include "MyDocClass.h"

use this:

class MyDocClass;

This makes your builds faster since changing one header file will not require everything to be re-compiled.