www.digitalmars.com         C & C++   DMDScript  

D - classes

reply "Michael" <imr1984 hotmail.com> writes:
Why must all classes be created on the heap in D ? Where is the logic in
that?

Michael
Jan 02 2004
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
 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 ---------------------------------------------------------------------------- ---
Jan 02 2004
parent "Ben Hinkle" <bhinkle4 juno.com> writes:
 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.
Jan 02 2004
prev sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
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.
Jan 02 2004