structs vs classes

Matthias Walter xammy at xammy.homelinux.net
Sat Jan 29 07:04:18 PST 2011


On 01/29/2011 09:13 AM, Jim wrote:
> so Wrote:
>
>>> I'm a bit troubled with the class/struct dichotomy. I would prefer them  
>>> both to use the same keyword. Heap/stack allocation could be specified  
>>> during instantiation instead. Why? Now you need to choose one over the  
>>> other. Not even C++ has this limitation.
>> This keeps coming and i have no idea how people think C++ treatment is any  
>> way good.
>> You are free to call the D design of struct/class the worst possible, but  
>> at least don't base your reasoning to C++ please.
>>
>> C++: both class and struct are exactly same, except one trivial:
>>
>> struct A : B {
>> };
>>
>> means:
>>
>> class A : public B {
>> public:
>> };
>>
>> In D they are quite different and they have different keywords.
>>
>> http://www.digitalmars.com/d/2.0/class.html
>> http://www.digitalmars.com/d/2.0/struct.html
> I'm only discussing the heap/stack difference.
>
That is of course a difference, but no argument. The reason is that you
can decide whether you want to allocate a class on the stack:

http://www.digitalmars.com/d/2.0/memory.html#stackclass

Matthias


More information about the Digitalmars-d mailing list