const(X) member of Y

Dan dbdavidson at yahoo.com
Wed Feb 6 14:00:51 PST 2013


On Wednesday, 6 February 2013 at 21:52:01 UTC, Maxim Fomin wrote:
>
> but this(const this) is supported and means to be a constructor

Maxim, please review this thread: 
http://forum.dlang.org/post/lrnxsvtwqwqtydggjphs@forum.dlang.org

In this example the 'this(const this)' is not called, just as 
pointed out in the previous thread. That is, things have not 
changed.
So, in following, "Hi" is not printed. Have you had any luck with 
'this(const this)'?

Thanks
Dan

import std.stdio;

struct X {
   char[] c;
   this(char[] c_) { c = c_.dup; }
   this(const this) {
     writeln("Hi");
   }
}

void main() {
   auto const x = X(['a']);
   const(X) x2 = x;
   writeln("Done");
}


More information about the Digitalmars-d mailing list