As everyone said in their answers. Its a bad idea and impossible.
You can only use tricks that no one knows how he will behave.
You can get a pointer to object A and overlay it with poiter of B.
Again, the only use of this is to show something else not to do.
A a; B* b = (B*)&a; b->bar();
source share