| |
|
Tom
| Hey guys,
having the following code:
# struct S
# {
# int m= 1234;
#
# static S* build_one() {
# auto new_inst= new S;
# return new_inst;
# }
#
# char[] myToString() {
# return format("(%s)={this=%x,m=%s}", typeof(this).stringof, this, m);
# }
#
# char[] toString() {
# return format("(%s)={this=%x,m=%s}", typeof(this).stringof, this, m);
# }
# }
# void main()
# {
# auto s= S.build_one();
# writefln("Builded a new instance at %x (%s)", s, s.myToString);
# writefln("Builded a new instance at %x (%s)", s, *s);
# writefln("Builded a new instance at %x (%s)", s, s.toString);
# }
The output was:
Builded a new instance at 910FE0 ((S *)={this=910FE0,m=1234})
Builded a new instance at 910FE0 ((S *)={this=13FEEC,m=1234})
Builded a new instance at 910FE0 ((S *)={this=910FE0,m=1234})
I wonder why is that in the second line, toString is printing an alternative this pointer?
Regards,
--
Tom;
|