c++ - Avoiding redefinition of a macro-defined class -


is there mechanism in c++ use implement macro such macro defines class , @ same time multiple invocations of macro not result in class redefinition error? thanks!

since macro cannot generate c++ preprocessor directives, there isn't way definition of macro generate #define protects if being re-generated. you'd have handle separate preprocessor controls, somehow:

#define class_generator_macro(x, y, z) ...defines class x attributes y, z...  #ifndef generated_class_a #define generated_class_a class_generator_macro(a, int, vector<std::string>); #endif /* generated_class_a */ 

however, there nothing automatically enforces 1 use of class_generator_macro create class a. is, file can contain:

class_generator_macro(a, double, double); 

and compiler complain redefinition of class (if both appear in same scope).

a macro can generate invocation of _pragma. there's outside chance system provides pragma can help. there isn't portable solution using pragmas.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -