class A
{
public:
void display()
{
cout << "class A\n";
}
};
class B
{
public:
void show()
{
cout << "class B\n";
}
};
int main()
{
A* aPtr = new A;
B* bPtr = new B;
B* bPtr2 = (B*) aPtr;
return 0;
}
In the above code why in C++ it is allowed to cast a pointer of one class type to another. Since the two class are not related still why B* bPtr2 = (B*) aPtr;
not throws an compile time error for casting the pointers of unrelated types.