Advertisement

multi classes with identical method

Started by January 14, 2001 11:07 AM
0 comments, last by ironfroggy 24 years ago
say i have class A. and i have classes B and C inherited from A. and i have a pointer P that could point to either a B or a C type object. And i have method D(int E); in both B and C. I then do this: P->D(1); will this call the method of the B or C type object, whichever it is pointing too at the time? psst.. did you see me post this on the graphics board by accident? oops! i forgot where i was..
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
let's see....

class A
{
/*...*/
virtual void fnc(int a) = 0;
/*...*/
};
class B : public A
{
/*...*/
virtual void fnc(int a) {/*whatever u want to do.*/};
/*...*/
}
class C : public A
{
/*...*/
virtual void fnc(int a) {{/*whatever u want to do.*/};
/*...*/
}

so u can do the following:

void someOtherFnc(A* pA);
{
pA->fnc(10);
}

but u cant do:
//...
A a; // compiler error: pure virtual members in a; u
// can't declare instances of A



Edited by - teneniel on January 14, 2001 12:31:33 PM

This topic is closed to new replies.

Advertisement