Object construction and this
Alexandr Druzhinin
drug2004 at bk.ru
Sun Nov 10 08:56:56 PST 2013
10.11.2013 23:22, Benjamin Thaut пишет:
> Am 10.11.2013 17:06, schrieb Alexandr Druzhinin:
>
> Because in D Classes are reference types. That means the code you wrote
> is equivalent to the following C++ source:
>
> class Foo
> {
> public:
> Foo(Object* o)
> {
> printf("%x\n", &this); // print a Foo**
> }
> }
>
> class Bar
> {
> public:
> Bar()
> {
> printf("%x\n", &this); // print a Bar**
> }
> }
>
> void main()
> {
> Object* o = new Object;
> Foo* foo = new Foo(o);
> printf("%x\n", &foo); // print a Foo**
>
> Bar* bar = new Bar();
> printf("%x\n", &bar); // print a Bar**
> }
>
> My best guess would be that you wanted to pass "this" instead of "&this"
> to writeln as weel as "bar" instead of "&bar" etc.
>
> Kind Regards
> Benjamin Thaut
Yes, of course I should pass this instead of &this, thanks. I was
looking for bug in wrong place - and using & let me hope I found it. :)
But kind people didn't let me get up on the wrong way. Thanks!
More information about the Digitalmars-d-learn
mailing list