On Wed, 16 Mar 2011 17:24:34 -0400, Simen kjaeraas
<[email protected]> wrote:
On Wed, 16 Mar 2011 22:05:49 +0100, Steven Schveighoffer
<[email protected]> wrote:
On Wed, 16 Mar 2011 16:49:53 -0400, Simen kjaeraas
<[email protected]> wrote:
On Wed, 16 Mar 2011 16:23:47 +0100, Steven Schveighoffer
<[email protected]> wrote:
struct Point2 {
int x, y;
void draw(Canvas c) {...}
}
struct Point3 : Point2 {
int z;
void draw(Canvas c) {...}
}
Point3 p3;
Point2 *p2 = &p3;
// what does this do?
p2.draw(c);
Nothing. You should got a type error upon attempting to assign a p3*
to a p2*.
The point is, if we allow inheritance on structs, it causes more
confusion to people who expect certain things from inheritance than it
beautifies syntax.
I agree. I also prefer alias this, both for its flexibility and its
distinctiveness. I just felt that the slicing problem is trivially fixed,
and thus need not be a part of the discussion.
The slicing problem is not encountered in this example. Pointing at the
base of a derived object does not slice the object. Your rule is too
strict ;)
-Steve