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

泪湿孤枕 提交于 2020-06-09 05:22:06

问题


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


回答1:


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)



来源:https://stackoverflow.com/questions/61546038/what-is-the-meaning-of-macro-in-front-of-class-definition-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!