Could you tell me how the error of the redefinition of this parameter came into being?

1. As shown in the figure, class b inherits class a, and the constructor of class b calls the constructor of a. The error of redefinition of formal parameter I appears where the arrow is hit

2.a(i)b

CPP
Mar.05,2021

in the first context, a (i); is a statement (statement), and the compiler parses it into a variable declaration, thus the local variable I has the same name as the function parameter.

according to syntax, it can be interpreted as function explicit type conversion or declaration , which is ambiguous. The standard convention interprets it as a declaration.

9.8.1 There is an ambiguity in the grammar involving expression-statements and declarations: An expression statement with a function-style explicit type conversion (8.2.3) as its leftmost subexpression can be indistinguishable from a declaration where the first declarator starts with a (. In those cases the statement is a declaration.

in the second context you give, a (i) means that ctor-initializer, does not have expression and declaration ambiguity.

Menu