struct inheritance need?

Weed resume755 at mail.ru
Tue Dec 16 17:55:09 PST 2008


Yigal Chripun пишет:

> 
> If I understand you correctly - I think you confuse here two separate 
> and orthogonal issues.
> 1) struct vs. class
> 2) memory allocation
> 
> What D tries to do is to provide types with value semantics via structs 
> and types with reference semantics _and_polymorphism_ via classes.
> IMO C++ is a prime example how to not design a language and the slicing 
> problem is a good example of that. value types should not have 
> polymorphism whatsoever as is done in D.
> 
> memory allocation is orthogonal to this:
> class C {...}
> Struct S {...}
> 
> auto c1 = new C; // classes default to heap alloc
> scope c2 = new C; // c2 is on stack
> S s1; // structs default to stack
> auto s2 = new S; // s2 is S* (heap alloc)
> 
> I think Andrei said he wants to make changes to "scope", that is IIRC.
> 

What will change?

> struct inheritance, if it gets implemented in D, should express IMO 
> semantics similar to concepts as in C++0x, not provide polymorphism for 
> value types which is clearly a mistake. (also this will remove the need 
> for typedefs, isn't it?)

I agree.
In my case I chose to structure rather than a class because it can be 
initialized at compile time.

But now I thing must be allowed to deploy class in the default data 
segment. And add the possibility of creating a object of class at 
compile time.
	
Nothing prevents this change?


More information about the Digitalmars-d-learn mailing list