Macro to class name

I recently looked at some code and I came across this:

class IDATA_EXPORT IData { /* .... */ } 

Where IDATA_EXPORT no more:

 #ifndef IDATA_EXPORT #define IDATA_EXPORT #endif 

What is IDATA_EXPORT in this case? (I mean, this is a type of type int, char, etc. ??)

+6
source share
1 answer

Most likely, at some point in time or under certain conditions, it was defined as (for example, under MSVC):

 #define IDATA_EXPORT __declspec(dllexport) 

which was used to specify classes for public export from the library.

Using a macro, a developer can alternate with exporting classes, rather than exporting something without having to iterate over each individual class.

This is often part of a macro template that alternates between importing and exporting classes, depending on whether the code is compiled from a library or from a library-dependent program. Then it will look something like this:

 #ifdef IS_LIBRARY // <--this would only be defined when compiling the library! #define IDATA_EXPORT __declspec(dllexport) #else #define IDATA_EXPORT __declspec(dllimport) #endif 

For more information, see dllexport, dllimport on MSDN

+6
source

All Articles