Base class to derive class access - How?
<p>How is it possible to access derived class's function through base classes object?
I have compiled and run the program without any error (vs2010 express edition).
Can any one give clarification regarding this topic? </p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
class A {
public:
    void f1() { cout &lt;&lt; " f1 \n"; }
};

class B : public A{
    int x;
public:
    void f2(int x) {this-&gt;x = x; cout &lt;&lt; "f2 " &lt;&lt; this-&gt;x &lt;&lt;"\n";}
};

int main(int argc, char * argv[])
{
    A * aaa = new A();    // created a base instance
    B * b = (B *) aaa;    // typecasted it to derived class
    b-&gt;f2(5);   // try to access function, which should not be possible (run-time error?)
    return 0;
}
</code></pre>

<p>--> output</p>

<pre><code>f2 5   // which concept is supports this output?
</code></pre>
