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

后端 未结 3 818
渐次进展
渐次进展 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.

提交回复
热议问题