Jump to page: 1 2
Thread overview
distinguish between classes and structures
Dec 15, 2008
Weed
Dec 15, 2008
Bill Baxter
Dec 15, 2008
Weed
Dec 15, 2008
Weed
Dec 15, 2008
Bill Baxter
Dec 15, 2008
Bill Baxter
Dec 15, 2008
Weed
Dec 15, 2008
Weed
Dec 15, 2008
Kagamin
Dec 16, 2008
Weed
Dec 16, 2008
Kagamin
Dec 16, 2008
Weed
Dec 15, 2008
Frits van Bommel
Dec 16, 2008
Weed
Dec 16, 2008
Bill Baxter
Dec 16, 2008
Weed
Dec 16, 2008
Weed
December 15, 2008
Who can provide a link to an explanation about why in D has taken to distinguish between classes and structures?

(Sorry for my bad English)
December 15, 2008
On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
> Who can provide a link to an explanation about why in D has taken to distinguish between classes and structures?
>
> (Sorry for my bad English)
>

The main justification is eliminating the slicing problem. http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html

D solves it by making it impossible to have a class instance as a value type.

--bb
December 15, 2008
Bill Baxter пишет:
> On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
>> Who can provide a link to an explanation about why in D has taken to
>> distinguish between classes and structures?
>>
>> (Sorry for my bad English)
>>
> 
> The main justification is eliminating the slicing problem.
> http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html
> 
> D solves it by making it impossible to have a class instance as a value type.
> 


Why not disallow the casting for structs, leaving the possibility of up casting for the links and pointers to the structure?
December 15, 2008
Weed пишет:
> Bill Baxter пишет:
>> On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
>>> Who can provide a link to an explanation about why in D has taken to
>>> distinguish between classes and structures?
>>>
>>> (Sorry for my bad English)
>>>
>>
>> The main justification is eliminating the slicing problem.
>> http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html 
>>
>>
>> D solves it by making it impossible to have a class instance as a value type.
>>
> 
> 
> Why not disallow the casting for structs, leaving the possibility of up casting for the links and pointers to the structure?

What is the best place for such questions?
December 15, 2008
2008/12/15 Weed <resume755@mail.ru>:
> Bill Baxter пишет:
>>
>> On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
>>>
>>> Who can provide a link to an explanation about why in D has taken to distinguish between classes and structures?
>>>
>>> (Sorry for my bad English)
>>>
>>
>> The main justification is eliminating the slicing problem.
>>
>> http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html
>>
>> D solves it by making it impossible to have a class instance as a value type.
>>
>
>
> Why not disallow the casting for structs, leaving the possibility of up casting for the links and pointers to the structure?

I have to confess I don't really understand this question.  Can you rephrase or give an example?

--bb

December 15, 2008
2008/12/15 Weed <resume755@mail.ru>:
> Weed пишет:
>>
>> Bill Baxter пишет:
>>>
>>> On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
>>>>
>>>> Who can provide a link to an explanation about why in D has taken to distinguish between classes and structures?
>>>>
>>>> (Sorry for my bad English)
>>>>
>>>
>>> The main justification is eliminating the slicing problem.
>>>
>>> http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html
>>>
>>> D solves it by making it impossible to have a class instance as a value type.
>>>
>>
>>
>> Why not disallow the casting for structs, leaving the possibility of up casting for the links and pointers to the structure?
>
> What is the best place for such questions?

Here is fine.  digitalmars.d might be ok too.

This seems like a question that deserves a good answer on the "rationale" page: http://www.digitalmars.com/d/2.0/rationale.html

I was just quoting to you the justification I've heard given before. But I'm not necessarily convinced that it's a net win for the language.  I find that it makes things simpler in some ways and more complicated in other ways.  But the "safety first" argument says that if it gets one potential bug (aka slicing), then its a net win.  I'm not so sure.

--bb

December 15, 2008
Bill Baxter пишет:
> 2008/12/15 Weed <resume755@mail.ru>:
>> Bill Baxter пишет:
>>> On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume755@mail.ru> wrote:
>>>> Who can provide a link to an explanation about why in D has taken to
>>>> distinguish between classes and structures?
>>>>
>>>> (Sorry for my bad English)
>>>>
>>> The main justification is eliminating the slicing problem.
>>>
>>> http://cplusplusgems.blogspot.com/2005/10/what-is-slicing-problem-class-base.html
>>>
>>> D solves it by making it impossible to have a class instance as a value
>>> type.
>>>
>>
>> Why not disallow the casting for structs, leaving the possibility of up
>> casting for the links and pointers to the structure?
> 
> I have to confess I don't really understand this question.  Can you
> rephrase or give an example?

Sorry, English is not my native language

In C++, we had the problem - "slicing" objects.
In D this problem is solved inability to inherit from structs.
Without inheritance of structs many things are not possible, compared with C++.
Why, instead of the complete inability to inherit, just do not make impossible to up casting struct type by value.

like this:

struct s1 {}
struct s2 : s1 {}

s1 base;
s2 derr;

s1* base_ptr = &derr; // ok
s1 val = derr; // error
December 15, 2008
Weed пишет:
> Why, instead of the complete inability to inherit, just do not make impossible to up casting struct type by value.

It's a question:
Why, instead of the complete inability to inherit, just do not make impossible to up casting struct type by value?
December 15, 2008
Weed Wrote:

> Without inheritance of structs many things are not possible, compared with C++.

for example?
December 15, 2008
Weed wrote:
> In C++, we had the problem - "slicing" objects.
> In D this problem is solved inability to inherit from structs.
> Without inheritance of structs many things are not possible, compared with C++.
> Why, instead of the complete inability to inherit, just do not make impossible to up casting struct type by value.
> 
> like this:
> 
> struct s1 {}
> struct s2 : s1 {}
> 
> s1 base;
> s2 derr;
> 
> s1* base_ptr = &derr; // ok
> s1 val = derr; // error

This is why:
  s1 val2 = *base_ptr; // error

(And disallowing '*ptr' on struct pointers is not likely to find much support)
« First   ‹ Prev
1 2