4

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

class MACRO class_name
{
     public :

     private :

}
Umair M
  • 10,298
  • 6
  • 42
  • 74
Arpit Jaiswal
  • 83
  • 1
  • 10

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
  • 111,498
  • 10
  • 176
  • 312
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
  • 418
  • 3
  • 12