#### Archived

This topic is now archived and is closed to further replies.

# Testing For A Class Name:..

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What i would like to do is create one Header file that i can include in all other .CPP files. Supposing that i want one of the CPP files to use only say half of the includes within this header, is it possible to test against the name of the class that the header is being called from using the pre-proceesor? Therefore excluding these headers from the build for that CPP. regards, ACE

##### Share on other sites
.H#ifndef DONTINCLUDEclass ..#endif
.CPP#define DONTINCLUDE // so this CPP won't include..#undef DONTINCLUDE // so other CPPs can include

--
You're Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..

[edited by - Pipo DeClown on May 9, 2004 9:01:11 AM]

[edited by - Pipo DeClown on May 9, 2004 9:01:35 AM]

##### Share on other sites
Including one global header file in each file is a lazy person''s way out of manually putting the header files you need. It can lead to circular dependencies and other such nasties. In short, don''t be so lazy and just include the headers you need. You''re lucky I''m even posting this, because I usually let people find out for themselves how bad it is.

##### Share on other sites
Pipo DeClown - CPP files (translation units) are all compiled separately. Macros defined in one translation unit have absolutely no effect whatsoever on other translation units.

ace_lovegrove - Use macro guards and pass the -DMYMACRO (or /DMYMACRO) option to the compiler:

#if defined(USE_FOO_VERSION_1)  class Foo {};#elif defined(USE_FOO_VERSION_2)  class Foo {};#else  #error You must define USE_FOO_VERSION_1 or USE_FOO_VERSION_1#endif

Command line: g++ -c -DUSE_FOO_VERSION_1 main.c or the equivalent for your compiler - see the docs.

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 12
• 15
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633354
• Total Posts
3011494
• ### Who's Online (See full list)

There are no registered users currently online

×