Why is separating class ind struct is bad?

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Sat Mar 26 01:53:00 PDT 2016


On Saturday, 26 March 2016 at 08:31:41 UTC, Jonathan M Davis 
wrote:
>  And while scoped may make sense in rare cases, pretty much by 
> definition, if you're putting an object on the heap, 
> polymorphism is not involved, and therefore it's completely 
> unnecessary to use a class.

That I disagree with too. Putting class on stack simply means 
that current scope will outlive the usage of class instance - it 
has nothing to do with polymorphism. It is one of many memory 
optimizations.

To explain a bit more, what I would consider convenient is to 
limit struct/class distinction to polymorphism exclusively, with 
not extra implications. So that you can still can do `MyClass 
on_stack;` (any `MyClass` is treated as type of object) but 
passing it to function wouldn't compile unless `ref` is also used.


More information about the Digitalmars-d mailing list