Why does this call the copy constructor 2 times and the assigment constructor once?
rempas
rempas at tutanota.com
Fri Nov 19 14:42:32 UTC 2021
On Friday, 19 November 2021 at 14:22:07 UTC, Paul Backus wrote:
>
> When you pass a struct instance to a function by value, or
> return a struct instance from a function by value, a copy is
> made, and the copy constructor is called.
>
> Your `opAssign` takes `rhs` by value, and returns a `str` by
>
> [...]
>
> Since `auto ref` is only allowed for template functions, I have
> added an empty template argument list (the `()`) to make
> `opAssign` into a function template.
>
> [...]
Interesting! It's weird that it works like that and explicitly
calls a constructor but it indeed works as expected now. Thanks a
lot and have an amazing day!
More information about the Digitalmars-d-learn
mailing list