In §8.2[dcl.ambig.res]/2 we have the following note (emphases is mine):
[ Note: A declaration can be explicitly disambiguated by a nonfunction-style cast, by an = to indicate initialization or by removing the redundant parentheses around the parameter name. —end note ]
Shouldn't it be inserting instead of removing above?
Consider the following example:
#include <iostream>
struct S{ int i; S(int j) : i(j) {} };
float f = 1.0f;
S s(int(f)); // function declaration
int main()
{
std::cout << s.i << '\n';
}
The code doesn't compile, as the compiler considers the declaration S s(int(f));
as a function declaration. But if we do insert the parenthesis around the parameter name f
, like S s((int(f)));
the code compiles and prints 1.
I have to agree with Simple's comment, it is telling you that the parentheses around the parameter name is redundant. This is reinforced by defect report 340: Unclear wording in disambiguation section which was closed as Not A Defect and gives the following example:
struct Point
{
Point(int){}
};
struct Lattice
{
Lattice(Point, Point, int){}
};
int main(void)
{
int a, b;
Lattice latt(Point(a), Point(b), 3); /* Line X */
}
and says:
The declaration of latt declares a function with a return value of the type Lattice and taking three arguments. The type of the first two arguments is Point and each of these arguments is followed by a parameter name in redundant parentheses. The type of the third argument can not be determined, because it is a literal. This will result in a syntax error.
I agree with Belloc 's argument. The Note could have been written with the following change (in bold) to give it a more precise meaning, an in this case the word remove
doesn't make sense.
An object declaration can be explicitly disambiguated by a nonfunction-style cast, by an = to indicate initialization or by removing inserting the redundant parentheses around the parameter name. —end note
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.