#1
  1. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15

    header files and VC++6


    My book says that to add preprocessor directives to prevent a file from being included more than once you can type them in your self, or select Tools/Macro and select OneTimeInclude in the Macro dialog box. When I try that, I find the Macro dialog box is totally blank. If I type in OneTimeInclude and hit return, I get an error saying I have to select a macro from the list--but the list is empty.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    You probably need to define the macro. Eitherway, it's trivial to code by hand:
    Code:
    #ifndef __FOO
    #define __FOO
    
    class Foo {
    };
    
    #endif
    Just pick an appropriate symbol to define. First you check to see if your symbol is not defined. If so, then you define it along with the class. If it is, then nothing is done.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    I think the macro provides random symbols to define so that each header file has a unique symbol. I'm going to download the service pack for VC++6 and see if that changes anything--it's only a 10.5 hour download after all.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Location
    Blacksburg VA/Philly PA
    Posts
    38
    Rep Power
    12
    It is considered good practice to use the name of the file in all capitals, and replacing the period (.) with an underscore (_)

    #ifndef EXAMPLE_H
    #define EXAMPLE_H

    .
    .
    .

    #endif
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Ok, I finally figured out how to access that macro. If anyone is interested:

    Without any files open in VC++6, you need to click on Tools/Macro, and in the Macro dialog box that appears, you have to click on Options then Loaded Files, and in the Customize dialog box that appears with the "Add-ins and Macro Files" tab selected, you need to enable the macro Sample by clicking on the check box, and then click on Close. Thereafter, when you click on Tools/Macro you can select Sample as the "Macro File:" from the drop down list, and then you'll be able to select OneTimeInclude from the list of macros. When you run that macro, it will automatically insert preprocessor directives in your .h file. There are also some other macros in the list that I'm sure would be useful too.

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo