Arpit Jaiswal
Arpit Jaiswal

Reputation: 83

Can there be anything between keyword 'class' and class name in c++?

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

class MACRO class_name
{
     public :

     private :

}

Upvotes: 4

Views: 1263

Answers (2)

Melkon
Melkon

Reputation: 428

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.

Upvotes: 5

Brian Bi
Brian Bi

Reputation: 119144

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.

Upvotes: 8

Related Questions