Skip to content

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

@xmh0511

Description

@xmh0511

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions