Re: Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread rempas via Digitalmars-d-learn
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 [...

Re: Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread Paul Backus via Digitalmars-d-learn
On Friday, 19 November 2021 at 14:05:40 UTC, rempas wrote: So, when I assign the value of the variable "name" in the "other_name", first it will call the copy constructor, then it will call the assignment constructor and then it will call the copy constructor again. Why is this happening? I was

Why does this call the copy constructor 2 times and the assigment constructor once?

2021-11-19 Thread rempas via Digitalmars-d-learn
Hi! I'm trying to make my own string type for my library. Anyway, I'm not very experienced with structs/classes so I don't understand what's going one here. I will not post the full code because I don't think that anyone would like it so I will just post the important parts that play a role (th