Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ macro "if class is defined"

Is there such macro in C++ (cross-compiler or compiler-specific):

#if isclass(NameSpace::MyClass)

Would be useful.

like image 802
topright gamedev Avatar asked Apr 20 '10 16:04

topright gamedev


3 Answers

No. Preprocessing directives and macros are evaluated by the preprocessor, which completes its tasks before the code is parsed as C++. The preprocessor has no knowledge of classes or namespaces.

like image 97
James McNellis Avatar answered Sep 19 '22 16:09

James McNellis


If you do not care about portability, the __if_exists statement in VC++ meets your needs.

like image 40
cuteCAT Avatar answered Sep 21 '22 16:09

cuteCAT


There is no such thing at the preprocessing stage, so no macro.

However you can have a look at the is_class type traits available in Boost or in C++0x that enable you to take decisions at compile time.

like image 39
Gregory Pakosz Avatar answered Sep 19 '22 16:09

Gregory Pakosz