4

I encountered a code in c++ where class has been defined like :

class MACRO class_name
{
     public :

     private :

}
Umair M
  • 9,448
  • 4
  • 38
  • 72
Arpit Jaiswal
  • 83
  • 1
  • 9

2 Answers2

8

In standard C++11 and later, there can be attributes between class and the class name. It is also possible (even more likely, perhaps) that the macro expands to non-standard attribute syntax supported by the particular compiler that is being used to compile the code.

Brian Bi
  • 102,989
  • 8
  • 160
  • 277
4

If you saw it on a Windows code, this is probably a macro which determine if you want to export or import the given class.

It's 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 PROJECTNAME_EXPORTS preprocessor definition should be defined, so the compiler will export the given class. If you compile a project which is just using the given dll, the ...EXPORTS won't be defined, so the compiler will import the given class.

Melkon
  • 408
  • 4
  • 12