I wanted to make a macro where I can pass the names of the classes and it will automatically create functions for those classes so they can be exported and dynamically loaded. I’m currently doing this in C++.
My problem now is that whenever I have ‘…’ as an argument, and then want to pass the arguments to another macro using __VA_ARGS_, Visual Studio Code tells me ‘this declaration has no storage class or type specifier’. Where is the error? Or how can it be solved in another way?
#define EXPORT_CLASS(Type)
extern "C" Type* create##Type() {
return new Type();
}
extern "C" void destroy##Type(Type* instance) {
delete instance;
}
#define EXPAND(x) x
#define EXPORT_CLASSES_IMPL(Type, ...)
EXPORT_CLASS(Type)
IF_NOT_EMPTY(__VA_ARGS__, EXPORT_CLASSES_IMPL(__VA_ARGS__))
#define EXPORT_CLASSES(...) EXPAND(EXPORT_CLASSES_IMPL(__VA_ARGS__)) //Called Macro
#define IF_NOT_EMPTY(Condition, ...) EXPAND(IF_NOT_EMPTY_IMPL(Condition, __VA_ARGS__))
#define IF_NOT_EMPTY_IMPL(Condition, ...) IF_NOT_EMPTY_##Condition(__VA_ARGS__)
#define IF_NOT_EMPTY_0(...)
#define IF_NOT_EMPTY_1(...) __VA_ARGS_
EXPORT_CLASSES(TestClass1, TestClass2) //Error here