Conversions around constructor syntax

12.1 / 1. Constructors have no names. The special declarator syntax using an optional sequence of specifier functions (7.1.2), followed by the name of the constructor class, followed by a list of parameters, is used to declare or define the constructor. In such a statement, the optional parentheses around the constructor class name are ignored.

Reading this text, I wonder what are the brackets around the constructor names in the following example that are ignored?

class MyClass { MyClass(); }; MyClass::MyClass() { } 
+4
source share
1 answer

There are no optional parentheses in the code snippet. The following example has optional parentheses around the constructor class name, and these parentheses are ignored:

 class MyClass { (MyClass)(); }; MyClass::MyClass() { } 
+6
source

Source: https://habr.com/ru/post/1389370/


All Articles