Passing a string by reference
Adam D Ruppe
destructionator at gmail.com
Tue Nov 8 12:43:47 UTC 2022
On Tuesday, 8 November 2022 at 12:30:50 UTC, Alexander Zhirov
wrote:
> Do I understand correctly that in order for me to pass a string
> when creating an object, I must pass it by value?
You should almost never use `ref string`. Just use plain `string`.
In fact, ref in general in D is a lot more rare than in languages
like C++. The main reason to use it for arrays is when you need
changes to the length to be visible to the caller... which is
fairly rare.
> In the case of the variable `c`, a drop occurs. Why? An object
> is not being created on the stack?
nope, an object isn't created there at all. you should use `new
C`.
More information about the Digitalmars-d-learn
mailing list