Thread overview
classes
Jan 02, 2004
Michael
Jan 02, 2004
Matthew
Jan 02, 2004
Ben Hinkle
Jan 02, 2004
J Anderson
January 02, 2004
Why must all classes be created on the heap in D ? Where is the logic in that?

Michael


January 02, 2004
> Why must all classes be created on the heap in D ?

They do not.

>  Where is the logic in
> that?

Not withstanding the lack of factual basis to your post, it sounds like you're more interested in having a whinge than asking a real question.

Nonetheless, I'll offer some reasons:

1. You don't have to worry about slicing
2. There's no opportunity for mis-aligned allocation
3. Non-RAII types can be garbage-collected which in most, although certainly
not all, circumstances can lead to performance improvements
4. There's no chance of holding dead-references to dead stack-based
instances.


ftr, there's no one right approach to most things in IT, and there is certainly no proven case that either stack-based or heap-based objects are superior to the other. Horses for courses.

Happy New Year


-- 
Matthew Wilson

STLSoft moderator (http://www.stlsoft.org)
Contributing editor, C/C++ Users Journal
(www.synesis.com.au/articles.html#columns)

"You can tell a Yorkshireman, but you can't tell him much!" -- Uncle Michael

----------------------------------------------------------------------------
---




January 02, 2004
Michael wrote:

>Why must all classes be created on the heap in D ? Where is the logic in
>that?
>
>Michael
>
>
>  
>
If you want a stackbased - like class use a struct.

January 02, 2004
> 1. You don't have to worry about slicing

Slicing is the worst part of C++ IMHO. You run into it ten seconds into the language and vow never to pass an object by value again.