Hi
today I mistaped a cast from void* to the wrong type
and everything was fine.
How can I check/realize that I am using the wrong class
or prevent cases like the one below?
Code:void main() { void *ptr; MyObject2* p2 = &obj2; ptr = p2; // here I casted to MyObject1 a pointer to // MyObject2... MyObject1* p1 = static_cast< MyObject1* >( ptr ); // ...and he works fine! It writes 20: // how to prevent this? p1->Mutator1( 20 ); } class MyObject1 { public: void Mutator1( int a ) { std::cout << a << std::endl; } }; class MyObject2 { public: void Mutator2( int a ) { std::cout << a << std::endl; } };