C++ Logo

std-proposals

Advanced search

Re: [std-proposals] c++ proposal

From: Rainer Deyke <rainerd_at_[hidden]>
Date: Wed, 1 Jul 2026 12:20:58 +0200
On 7/1/26 10:08, Jonathan Wakely wrote:
>> This solves a real problem, but I am not convinced that it solves it
>> better than the idiomatic workaround, nor that the problem is common
>> enough to justify a change in the language. The idiomatic workaround:
>>
>> class base {
>> public:
>> base(int) { this->init(); }
>> protected:
>> base() = default;
>> virtual void f() {}
>> void init() {
>> this->f();
>> }
>> };
>>
>> class derived1 : public base {
>> public:
>> derived1(int n) : base(n) {
>>
>
> Checking I understand the idiom you're describing:
> Is this meant to call base() to avoid using init() twice?

Yes it is. Thanks for pointing that out. The idiom is very prone to
making exactly that mistake, which I concede is a major advantage of the
proposed new syntax.

>
> this->init();
>> }
>> protected:
>> derived1() = default;
>> void f() override {}
>> };
>>
>> class derived2 final : public base {
>> public:
>> derived2(int n) : derived1(n) {
>>
>
> And same here?

Yes.

>
> this->init();
>> }
>> protected:
>> void f() override {}
>> }
-- 
Rainer Deyke - rainerd_at_[hidden]

Received on 2026-07-01 10:21:07