Signal and slot trouble

bearophile bearophileHUGS at lycos.com
Sun Nov 21 12:13:31 PST 2010


Peter Federighi:

> So, on the thought that the global declaration of the class just creates an
> instance and doesn't actually allocate it in memory,

In code like:

class Foo {}
void main() {
    Foo x;
}

x isn't an instance, it is just an empty (null) reference to class instances.


> What's with D not actually allocating a class in a declaration?  Isn't that
> syntactically odd?  If I say 'int x' , I get an int.  I don't have to say 'int x =
> new int'.  So, it seems logical to me that I should be able to say 'MyClass mc'
> and get a MyClass.

In D structs are values, so in this code x is an instance of Foo, on the stack:

Struct Foo {}
void main() {
    Foo x;
}

But in D objects are reference types, they are always composed by a reference that points to the instance (as in Java) that is often on the heap.
To avoid other bugs/troubles, I suggest you to read the basics about D from the site.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list