Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dcl.fct] p6 Does it make sense that a constructor can have an explicit object parameter? #5420

Closed
xmh0511 opened this issue Apr 27, 2022 · 1 comment · Fixed by #6119
Closed

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Apr 27, 2022

The limitation for a function that can have an explicit object parameter is defined as

An explicit-object-parameter-declaration is a parameter-declaration with a this specifier. An explicit-object-parameter-declaration shall appear only as the first parameter-declaration of a parameter-declaration-list of either:

  • a member-declarator that declares a member function ([class.mem]), or
  • a lambda-declarator ([expr.prim.lambda]).

A member-declarator with an explicit-object-parameter-declaration shall not include a ref-qualifier or a cv-qualifier-seq and shall not be declared static or virtual.

Consider a constructor of a class, which satisfies all bullets regulated above. Namely, the constructor can have an explicit object parameter, is this reasonable? Since in the call of a constructor, there never exists an implicit object argument to match the object parameter. From this perspective, a constructor with an explicit object parameter is similar to a non-member function with that object parameter, the latter does make no sense and is forbidden by the above rule.

@frederick-vs-ja
Copy link
Contributor

Resolved by CWG2674.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants