Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

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
};

I cannot understand the syntax class Q_MONKEY_EXPORT BasePlugin. To me it looks like if there are two names for the class. What exactly does this kind of syntax mean in C++?

like image 888
Amani Avatar asked Oct 20 '11 19:10

Amani


People also ask

Can 2 classes have same name in C++?

Both declare classes with the same name, but perhaps a totally different structure (or perhaps the same structure, different implementation). The classes do not appear in the header files. (As an example, suppose they are Node classes for different list classes.)

What is a class declaration?

The class declaration component declares the name of the class along with other attributes such as the class's superclass, and whether the class is public, final, or abstract. At minimum, the class declaration must contain the class keyword and the name of the class that you are defining.

Has the same name as the class in which it is declared?

Answer: A constructor is a special kind of subroutine in a class. It has the same name as the name of the class, and it has no return type, not even void. A constructor is called with the new operator in order to create a new object.

What is a class declaration in C++?

A class declaration creates a unique type class name. A class specifier is a type specifier used to declare a class. Once a class specifier has been seen and its members declared, a class is considered to be defined even if the member functions of that class are not yet defined.


1 Answers

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).

like image 120
Dabbler Avatar answered Sep 29 '22 08:09

Dabbler