gpt4 book ai didi

c++ - 初始化数据成员的列表的正确术语是什么?

转载 作者:可可西里 更新时间:2023-11-01 16:28:03 26 4
gpt4 key购买 nike

  • 一个同事说initializer list,另一个initialization列表
  • 一个SO answerinitializer list,另一个initialization列表

哪个是正确的*术语?

PS:他们都在谈论数据成员初始化器/列表。


*如果您对正确性有歧义,您可以回退到作为标准使用的术语。

最佳答案

Which is the correct terminology?

“正确”含糊不清,让我们看看:

  1. 标准称之为,
  2. C++ 专家称之为,
  3. vulgus调用它。

标准

[lass.base.init]/1&2

1 In the definition of a constructor for a class, initializers for direct and virtual base class subobjects and non-static data members can be specified by a ctor-initializer, which has the form

ctor-initializer:
: mem-initializer-list

mem-initializer-list:
mem-initializer ...opt
mem-initializer-list , mem-initializer ...opt

mem-initializer:
mem-initializer-id ( expression-list opt )
mem-initializer-id braced-init-list

mem-initializer-id:
class-or-decltype
identifier

2 In a mem-initializer-id an initial unqualified identifier is looked up in the scope of the constructor's class and, if not found in that scope, it is looked up in the scope containing the constructor's definition. [ Note: If the constructor's class contains a member with the same name as a direct or virtual base class of the class, a mem-initializer-id naming the member or base class and composed of a single identifier refers to the class member. A mem-initializer-id for the hidden base class may be specified using a qualified name. — end note ] Unless the mem-initializer-id names the constructor's class, a non-static data member of the constructor's class, or a direct or virtual base of that class, the mem-initializer is ill-formed.

它叫做mem-initializer-list:这是一个我个人不会使用的技术术语。

C++ 大师

我目前正在观看 Herb Sutter、Kate Gregory、Timur Doumler、John Lakos 等人在 CppCon2018 上发表的演讲……这在 Youtube 上可用,我建议您也观看。

他们使用术语初始化列表。或者当它不明确时成员初始化列表

现在,让我们比较一些搜索结果:

                               +----------------+-------------+
| Google scholar | Google book |
+------------------------------+----------------+-------------+
| "member initialization list" | 59 results | 948 results |
| "member initializer list" | 34 results | 553 results |
+------------------------------+----------------+-------------+

在书面媒体上,那些专家(好吧,每个人都可以写论文或书,但专家往往写得更多)大部分时间都将其称为成员初始化列表。 p>

普通C++程序员

好吧,有些人不知道这是什么,而我听说有一种人称它为初始化程序列表。我称它为初始化列表,即使是在用我的母语交谈时也是如此。在法语中,我听说同事将其称为初始化列表。我想会有一些变化。

结论

称它为初始化列表。这对我来说是正确的术语。

关于c++ - 初始化数据成员的列表的正确术语是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53444145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com