gpt4 book ai didi

c++ - 构造函数语法周围的括号

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:52 25 4
gpt4 key购买 nike

12.1/1. Constructors do not have names. A special declarator syntax using an optional sequence of function-specifiers (7.1.2) followed by the constructor’s class name followed by a parameter list is used to declare or define the constructor. In such a declaration, optional parentheses around the constructor class name are ignored.

阅读该文本,我想知道在以下示例中被忽略的构造函数名称周围的括号是什么?

class MyClass
{
MyClass();
};

MyClass::MyClass() {
}

最佳答案

您的代码片段中没有可选的括号。以下示例在构造函数类名周围有可选括号,这些括号将被忽略:

class MyClass
{
(MyClass)();
};

MyClass::MyClass() { }

关于c++ - 构造函数语法周围的括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8735527/

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