I am a newbie in C++. Can anyone tell me why the following source code runs well?
#include <iostream>
using namespace std;
class A{
public:
    A(){ cout << "create a" << endl; }
    void sayGoodbye() { cout << "goodbye" << endl; }
};
class B{
public:
    B() { cout << "create b" << endl; }
    void sayHello() { cout << "hello" << endl; }
};
int main(array<System::String ^> ^args)
{
    A* a = new A();
    ((B*)a)->sayHello();
    a->sayGoodbye();
    return 0;
}
Output:
create a
hello
goodbye
What I wonder is why can the a access B::sayHello just by casting like that? Can it access every public members of any class by that way?
 
     
     
     
     
     
     
    