Victor Bazarov <> wrote in message
news:HPNKa.27749$Ab2.52246@sccrnsc01...
> "David White" <> wrote...
> > My argument was in the context of the example that _I_ gave. Why give a
> > completely different one?
>
> Because when you started arguing, there was no example. Why
> should the language behave differently with different examples?
> There would be no consistency, no logic.
>
> >
> > class Base
> > {
> > public:
> > void func();
> > //...
> > };
> >
> > class Derived : public Base
> > {
> > public:
> > void func();
> > //...
> > };
> >
> > void f()
> > {
> > Derived d;
> > Base *pBase = &d;
> > Derived *pDerived = &d;
> > pBase->func();
> > pDerived->func();
> > }
> >
> > Aside from the pointers, how many objects have been created here? One, a
> > Derived. That's all.
>
> No, there are two objects. One inside the other. B inside D.
> As soon as you stop being so irrationally stubborn, you might
> actually begin to understand...
There is ONE object. One D. That's what you created.
> >
> > Nevertheless, I'll look at yours.
>
> Why, thank you.
>
> >
> > > #include <iostream>
> > >
> > > struct A {
> > > double foo;
> > > };
> > >
> > > struct B {
> > > int a;
> > > void func() {
> > > std::cout << (void*)this << std::endl;
> > > }
> > > };
> > >
> > > struct D : A, B {
> > > void func() {
> > > std::cout << (void*)this << std::endl;
> > > }
> > > };
> > >
> > > int main() {
> > > D d;
> >
> > Only one object here, a D.
>
> Well, no. One D. And inside it there are four more. One A
> (and inside it a double), one B (and an int inside it).
Wrong. There is only a D.
> >
> > > D *pd = &d;
> >
> > Points to the D part of d, which of course includes the A and B parts,
> which
> > it inherits.
>
> "Parts"? Are they not objects?
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?
> >
> > > B *pb = &d;
> >
> > Points to the B part of d, which might or might not have the same
address
> as
> > the D part. In any case, we are still pointing to a D, because that's
the
> > type that d is.
>
> Nope. It's what is known as a "B subobject of D". Whether you call
> it "part" or otherwise, doesn't matter. You are not "still pointing
> to a D".
Yes, you are. d is a D, so you are pointing to a D.
> You're pointing to a different object. Repeat after me:
> "pb points to a different object".
I'm not going to repeat something that's wrong. I suggest you repeat this:
"pb points to the same object"
> If you convert a D* into A*, does
> it still point 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.
> Are you able to pass A* where
> B* is expected? No. Why? Because they are not the same object.
>
> >
> > > void *p = pd;
> >
> > Converts the address of d to void*, with who-knows what result.
>
> The Standard know what result is. If I convert it to void*
> and then back to D*, the value doesn't change. You seem to be
> in need of a good C++ study, mate.
>
> >
> > > std::cout << "As D : " << p << std::endl;
> > > p = pb;
> > > std::cout << "As B : " << p << std::endl;
> > > pd->func();
> > > pb->func();
> > > }
> > >
> > > Does it output the same address? If it doesn't, how can
> > > "the same object" have different addresses?
> >
> > Because you are pointing to different parts of the _same_ object. So
what?
>
> You're starting to get there.
Being a sarcastic arsehole generally doesn't facilitate constructive
discussions.
> I can understand how you don't want to give up your mole-hill.
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.
> "I did C++ for 8 years and I know that it's full of it, all wrong
> and [how did you put it?... Ah] intuitively objectionable".
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.
> Give it up. You have still a significant part of the language to learn.
I won't disagree with that, but it doesn't include the nonsense you've been
saying in your last couple of posts.
> Try not to think that what your "instinct" is telling you is the
> ultimate truth.
I've said nothing about the "ultimate truth". I've been expressing an
opinion on a specific usage.
> Let your "instinct" grow with you as you study the
> language instead of objecting to its features.
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