What does it mean when a class declaration appears to have two names?

后端 未结 3 783
渐次进展
渐次进展 2021-02-05 17:49

I\'m trying to understand some C++ code which has the following class syntax:

class Q_MONKEY_EXPORT BasePlugin : public QObject
{
    // some code comes here
};
         


        
相关标签:
3条回答
  • 2021-02-05 18:28

    That's most probably a preprocessor directive telling the compiler the symbol is to be exported.

    It's probably defined as:

    #define Q_MONKEY_EXPORT _declspec(dllexport)
    

    which will cause your class to be exported to the dll.

    The full declaration will be expanded, before compilation, to:

    class _declspec(dllimport) BasePlugin : public QObject
    {
        // some code comes here
    };
    

    EDIT:

    As David Heffernan pointed out, macros like these are generally used to let the compiler know whether it needs to import or export the symbols. Usually defined as dllimport for outside modules and dllexport when building the module. I doubt that's the case here, since the name suggests exporting, but it's best to check the documentation or actually go to the definition.

    0 讨论(0)
  • 2021-02-05 18:30

    Q_MONKEY_EXPORT is most likely a #define somewhere. Defines like that are sometimes required, for example when the class is in a library and needs to be exported when the header file is included from somewhere else. In that case, the define resolves to something like __declspec(dllexport) (the exact syntax will depend on the tools you are using).

    0 讨论(0)
  • 2021-02-05 18:43

    Q_MONKEY_EXPORT is a macro (all upper case is convention for macro) that typically resolves to something like __declspec(dllexport) when you are building the DLL and resolves to __declspec(dllimport) when you are using the DLL.

    You can find out exactly what it is by reading your include files.

    0 讨论(0)
提交回复
热议问题