Confused about non-virtual functions
There is ONE object. One D. That's what you created.
Wrong. There is only a D.
No, they are not. Suppose you have a class Shape, which is abstract, and
from it you derive a class Ellipse. If you have a Shape* that points to an
Ellipse, you are not pointing to a Shape object, because there is no such
thing. You are pointing to the Shape part of an Ellipse. After all, that's
what you made, an Ellipse. Further, I suggest that on most implementations
the Shape* and Ellipse* would be the same address. Does that mean, according
to your own reasoning, that they point to the same object?
Yes, you are. d is a D, so you are pointing to a D.
I'm not going to repeat something that's wrong. I suggest you repeat this:
"pb points to the same object"
Yes, it still points to d, which is a D. To prove that it does, add a
virtual function to A that is overridden in D. Whether you call the function
through an A* or a D* the result is the same: it calls the function in D.
That's because the object you are pointing to is a D.
Being a sarcastic arsehole generally doesn't facilitate constructive discussions.
I've expressed an _opinion_ as to the usage of identical, non-virtual
functions in base and derived classes, and I've given my reasons.
Instinctively. And I was referring only to the usage we are discussing.
Where did "I know that it's full of it, all wrong" come from? Not from me,
even though you've presented this crap as a quote from me.
I said that I had not seen the usage we are discussing in 8 years of
programming C++. I neither stated nor implied anything else. I even
qualified what I've come across in that time with "Maybe I'm too sheltered,
but that's my experience." Perhaps you can explain how you managed to turn
that into the bullshit above.
I won't disagree with that, but it doesn't include the nonsense you've been
saying in your last couple of posts.
I've said nothing about the "ultimate truth". I've been expressing an
opinion on a specific usage.
My instinct can say what it likes. I am entitled to dislike a usage that is
easily missed because it's rare and contradicts the concept of IS-A in OO
programming.
David
|