C++ Logo

std-proposals

Advanced search

[std-proposals] P2287R4 Designated initializers for Base Classes - Double Colon

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 25 Mar 2025 09:25:08 +0000
In Barry's paper, he gives the following example:

  struct A { int a; };

  struct B : A { int b; };

  // provide a way to name the base class
  auto b1 = B{.A={.a=1}, .b=2};

I think "." should be used for members, and that "::" should be used
for base classes, as follows:

    auto b1 = B{ A::={.a=1}, .b=2 };

I am proposing this change for two reasons:
1) It is easier to see at a glance what is a base class and what is a member
2) It accommodates weird situations such as:

  struct Base { int a };
  struct Derived : Base { vector<int> Base; };

In this situation we don't know if 'Base' is a member or a base class,
and so the use of "." Vs "::" will clarify things.

Received on 2025-03-25 09:25:17