How to re-type pointer to a class and be able to reach classes functions based on it's type?
<p>I'm writing a C++ code which should populate a screen (and it's behaviour) based on a function from the object pointer was initiated with. Let's better show it on a code:</p>

<pre><code>class A:parentClass {
public:
    int X () {return 5;}
}

class B:parentClass {
public:
    int X () {return 3;}
}

class C:parentClass {
public:
    int X () {return 1;}
}

main {
    parentClass *p;
    p = new A;
    printf("%d\n,p.x); //to return 5
    delete p;
    p = new B;
    printf("%d\n,p.x); //to return 3
}
</code></pre>

<p>I'm getting something like this on compilation: </p>

<pre><code>‘class parrentClass’ has no member named ‘x’
</code></pre>

<p>I know that this is wrong, as parrentClass simply doesn't have that member, but I don't have an idea how to solve this. I tried to go through templates, but I'm not getting anywhere. </p>

<p>I also tried to replace "parentClass *p;" with "int *p;", but then I'm getting:</p>

<pre><code>cannot convert ‘CardsFrame*’ to ‘int*’ 
</code></pre>

<p>Thanks for your suggestions in advance,</p>

<p>Jan</p>
