C ++中类定义前面的宏是什么意思 [英] What is the meaning of macro in front of class definition in c++

查看:99
本文介绍了C ++中类定义前面的宏是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中允许以下构造的语法是什么,在 class和 class_name之间出现一个单词?

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;

还请注意以下有关语法的问题和答案与其他有关:
在c ++中的类定义前面的宏
C ++类定义语法

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

推荐答案

它不是标准的C ++(除非宏评估为空格,或者您使用的是属性),但是某些编译器在针对特定平台时需要使用它。

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.

常见的情况是在为Windows构建动态链接库(dll)时。生成dll时, OCTINTERP_API 可能设置为 __ declspec(dllexport),而 __ declspec(dllimport )(使用dll时)。

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.

(请参见 https://en.cppreference.com/w/cpp/language/classes

这篇关于C ++中类定义前面的宏是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆