CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Can't include Document header file in new class!

    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


  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Can't include Document header file in new class!

    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



  3. #3
    Join Date
    Apr 1999
    Location
    Alabama, USA
    Posts
    261

    Re: Can't include Document header file in new class!

    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.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured