b.hello() prints "x" because b is an instance of class X. c->hello() prints "y" because c points to a , and a is an instance of class Y.
What may confuse you is that when you write xb = a; , you create a new object b and initialize it a . When you write x* c = &a; , c not a new object. You simply entered the alias of an existing object.
Karmastan
source share