Pointer to a class member
negerns
negerns2000 at gmail.com
Mon Aug 20 13:23:45 PDT 2007
negerns wrote:
> 0ffh wrote:
>
>>
>> module test;
>>
>> import std.stdio;
>>
>> class A {
>> char[] _name;
>> public this(char[] n) { _name = n; }
>> public char[]* get() { return (&_name); }
>> public void show() { writefln(_name); }
>> }
>>
>> void main() {
>> auto a = new A("digitalmars");
>>
>> // I wanted a variable here to point to A._name's value
>> // and manipulate it and expect the A._name's value to
>> // reflect that change. Something like:
>> char[]* p = a.get();
>> *p ~= ".com";
>>
>> // and excpect a._name's value becomes "digitalmars.com"
>> a.show();
>> }
>
> How do I display the value of a._name using the variable *p?
Please tell me if the following code is doing something illegal or is
not a good way to do it.
writefln(cast(char[])*b);
--
negerns
More information about the Digitalmars-d-learn
mailing list