user3196256
user3196256

Reputation: 23

What is the meaning of macro in front of class definition in c++

What is the syntax in C++ that allows the following construction, where a word appears in between "class" and "class_name"?

namespace octave
{
  // Command line arguments.  See also options-usage.h.

  class OCTINTERP_API cmdline_options
  {
  public:
...

Note, I am not asking the meaning of the macro. I am not asking what it does. I am not asking if it is empty. I am asking about the syntax of class definition.

Several sources explain the syntax, but without the word in the middle, for example:

class class_name {
  access_specifier_1:
    member1;
  access_specifier_2:
    member2;
  ...
} object_names;

Note also that the following questions asked about the syntax and the answers were about something else: macro in front of class definition in c++ and C++ Class definition syntax

Upvotes: 0

Views: 96

Answers (1)

Bathsheba
Bathsheba

Reputation: 234635

It's not standard C++ (unless the macro evaluates to whitespace, or you're using attributes) but it's required by some compilers when targeting certain platforms.

A common occurrence is when building a dynamic linked library (dll) for Windows. OCTINTERP_API is likely set to __declspec(dllexport) when building the dll, and __declspec(dllimport) when using the dll.

(See https://en.cppreference.com/w/cpp/language/classes)

Upvotes: 5

Related Questions