Copy Constructor DIP and implementation
Nicholas Wilson
iamthewilsonator at hotmail.com
Tue Sep 25 01:59:36 UTC 2018
On Monday, 24 September 2018 at 23:22:13 UTC, Jonathan M Davis
wrote:
> @implicit on copy constructors is outright bad. It would just
> be a source of bugs. Every time that someone forgets to use it
> (which plenty of programmers will forget, just like they forget
> to use @safe, pure, nothrow, etc.), they're going to have a bug
> in their program. However, unlike, with attributes like @safe
> or pure, they're not going to get a compiler error in their
> program; they're going to get a logic error. They may or may
> not find that bug quickly, but the compiler isn't going to
> point it out to them.
I think this is the most important reason. In C++, where
everything is implicit by default (which is bad) and (I think)
you are encouraged to use explicit where possible, you should
never use it for the copy constructor because the compiler always
calls it implicitly for you and is the whole point of having:
Foo a; Foo b = a;
do something useful. Putting explicit on the copy ctor means that
no longer works, one can then only use it with
Foo a; Foo b(a);
Having `Foo a; Foo b = a;` do something completely different by
the addition or removal of one attribute is a serious problem
just waiting to happen.
More information about the Digitalmars-d-announce
mailing list