C++ custom class limited functionality -


let's have custom class defined, there's function inside class want use if , if header file defined in main application.

in words: not want use functionality custom defined class unless special header file included in main application.

if have custom class definition inside main app. use #ifdef _some_stuff_h , #endif. doesn't work inside header file (why guess?).

the question itself: trying achieve complete non-sense , should include required headers?

apologies if problem not sound clear.

code example of class (assuming class defined in main app.):

class someclass { public:     void dothis();      #ifdef _some_header_h     //uses stuff some_header.h     void dothat();     #endif };  void someclass::dothis() {}  #ifdef _some_header_h //uses stuff some_header.h void someclass::dothat() {} #endif 

compilies , works fine, etc.

in case separate class header , source include someclass in main.

if build solution when custom class in main app. compile whether some_stuff.h included or not (as should). if build other way (not including some_stuff.h in custom-class header including in main app.) gives "unresolved external symbol".

why assume #ifdef wouldn't work? header files aren't special; they're source code, preprocessed , compiled else. make sure headers organized respect dependencies, i.e. if a.h depends on b.h, b.h needs included first. applies regardless.


Comments