C++ Logo

std-proposals

Advanced search

[std-proposals] Pass derived object by reference to single parameter delegated templated constructors

From: David wang <wangjufan_at_[hidden]>
Date: Thu, 9 May 2024 17:07:36 +0800
On Tue, 7 May 2024 17:04:14 +0200 Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> wrote:

>Or are you looking for a way to specify an explicit template constructor
argument list? Possibly with T& reference type?

No.

On Wed, 8 May 2024 09:44:28 +0200 Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> wrote:

>If the construct automatically always leads to stack overflow errors, one
could - as a third option - disallow it altogether.
>Something like a default copy constructor may not be called from a derived
class with a parameter passed by value.

What's the key point?

>So the programmer would have to solve it explicitly. This would be the
better alternative than to make a surprising special case.

In fact, the C++ standard can remove the & symbol from the copy
constructor, and preserve the reference semantics by associating them to
the class name in the constructor definition. This simplifies copy
constructors' syntax by unifying them. I will try my best to complete it in
the coming days.

>Can the compiler detect those cases at least most of the time?

Yes, the compiler detects all cases。

Received on 2024-05-09 09:07:49