Difference between stack-allocated class and struct

Mariusz Gliwiński alienballance at gmail.com
Mon May 2 15:15:21 PDT 2011


Firstly, thanks for comprehensive answer and I'd like to excuse for my 
stupid mistakes, which are caused by learning a lot and not actually 
programming.

On date 2011-05-02 23:03, Jonathan M Davis wrote:
> Classes are reference types and are meant to be on the heap.
Yeah, value vs reference semantics - that was the thing i forgot...
> So, if you're using a scoped class, you're _not_ getting the benefits of
> polymorphism.
I completely didn't think about, that stack size needs to be known 
already at time of compiling. You just probably saved me a lot of problems.


So, scoped classes can't be used for filling gap in struct inheritance.

I'll clarify myself:
All i would need is extending - without polymorphism.
Containment, can be solution for fields which doesn't annoys so much 
(although image in auto-generated documentation, just like it's with 
subclassing, would be nice).
Unfortunately, the worse case is about methods, which have to be 
manually forwarded to contained struct.

So, does someone sees any nice solution for method forwarding as 
described? Should i make use of some mixin's?

Thanks,
Mariusz Gliwiński


More information about the Digitalmars-d-learn mailing list