Consider this:
#include <iostream>
using namespace std;
class A{
protected:
void some_function(int params)
{
//inside A: do something A related
}
};
class B: public A{
public:
void call_some_function(int params)
{
some_function(params); // Simple call to A::some_function and NOTHING MORE.
}
};
int main(int argc, char *argv[])
{
A* a = new A();
((B*)(a))->call_some_function(20); // Is it OK ?
}
This code works
What is the danger of using it ?
One danger is that
call_some_functioncan only call functions (or access members in general) inA. All access to a member ofBwill result in access outside of allocated memory, with probably disastrous consequences.