I've been experimenting with pointers and written the following code:
#include <iostream>
using std::cout;
struct A
{
int a;
char b;
A(){ a = 4; }
};
struct B
{
int c;
B(){ c = 5; }
};
A *a = new A;
B *b = new B;
int main()
{
a = (A*)b;
cout << a -> a; //5
}
Why B*
can be converted to A*
? Can any pointer be converted to any other pointer?