Bill Baxter пишет:
2008/12/15 Weed <resume...@mail.ru>:
Bill Baxter пишет:
On Mon, Dec 15, 2008 at 3:35 PM, Weed <resume...@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

Reply via email to