Could there be something between the keyword "class" and the class name in C ++?

I came across a code in C ++ where the class was defined as:

class MACRO class_name
{
     public :

     private :

}

      

+3


source to share


2 answers


If you've seen this in Windows code, it's probably a macro that determines whether you want to export or import a given class.

This is very common if you are dealing with dll-s.

So this macro is probably something like this:



#ifdef  PROJECTNAME_EXPORTS

#define MACROBEFORECLASSNAME __declspec(dllexport)
#else
#define MACROBEFORECLASSNAME __declspec(dllimport)
#endif

      

If you compile the dll, the preprocessor definition PROJECTNAME_EXPORTS must be defined, so the compiler will export this class. If you compile a project that only uses this DLL, then ... EXPORTS will not be defined, so the compiler will import this class.

+4


source


In standard C ++ 11 and later, there can be attributes between class

and the class name. It is also possible (and even more likely, possible) that the macro expands to a non-standard attribute syntax supported by the particular compiler that is used to compile the code.



+8


source







All Articles