digitalmars.D - Append char to char-array in function
- Nrgyzer (22/22) Mar 21 2010 Hello everyone,
- Bane (10/43) Mar 21 2010 No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref'...
- bearophile (4/5) Mar 21 2010 Use 'ref' only. If the OP also wants to know why that's the solution, th...
- Bane (2/9) Mar 21 2010 Darn. I like inout more. Why do good keywords die first?
- Robert Clipsham (4/13) Mar 21 2010 inout still works in D1, in D2 it has a new meaning though to save
- Nrgyzer (2/51) Mar 21 2010 Thanks, that's exactly what I needed :)
Hello everyone, how can I add a char to a char-array by using a other class? For example: class A { private char[] text; this() { ... text ~= "a"; new B(text); writefln(text); ... } } class B { this(char[] text) { ... text ~= "b"; ... } } This should write "ab" in the command line, but only "a" is shown. ... Thanks for help :).
Mar 21 2010
Nrgyzer Wrote:Hello everyone, how can I add a char to a char-array by using a other class? For example: class A { private char[] text; this() { ... text ~= "a"; new B(text); writefln(text); ... } } class B { this(char[] text) { ... text ~= "b"; ... } } This should write "ab" in the command line, but only "a" is shown. ... Thanks for help :).No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref' or 'inout' keyword it might work: class B { this(inout char[] text) { ... text ~= "b"; ... } }
Mar 21 2010
Bane:No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref' or 'inout' keyword it might work:Use 'ref' only. If the OP also wants to know why that's the solution, the d.learn newsgroup is the right place to ask. Bye, bearophile
Mar 21 2010
bearophile Wrote:Bane:Darn. I like inout more. Why do good keywords die first?No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref' or 'inout' keyword it might work:Use 'ref' only. If the OP also wants to know why that's the solution, the d.learn newsgroup is the right place to ask. Bye, bearophile
Mar 21 2010
On 21/03/10 11:40, Bane wrote:bearophile Wrote:inout still works in D1, in D2 it has a new meaning though to save writing out a function 3 times for const/immutable/mutable (http://www.digitalmars.com/d/2.0/function.html#inout-functions).Bane:Darn. I like inout more. Why do good keywords die first?No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref' or 'inout' keyword it might work:Use 'ref' only. If the OP also wants to know why that's the solution, the d.learn newsgroup is the right place to ask. Bye, bearophile
Mar 21 2010
Bane Wrote:Nrgyzer Wrote:Thanks, that's exactly what I needed :)Hello everyone, how can I add a char to a char-array by using a other class? For example: class A { private char[] text; this() { ... text ~= "a"; new B(text); writefln(text); ... } } class B { this(char[] text) { ... text ~= "b"; ... } } This should write "ab" in the command line, but only "a" is shown. ... Thanks for help :).No, it shouldn't. What goes in B, stays in B. But if you add magic 'ref' or 'inout' keyword it might work: class B { this(inout char[] text) { ... text ~= "b"; ... } }
Mar 21 2010