我正在尝试使用从接口继承的子类的方法。从客户端类(主方法)对该方法的调用。//接口方法
class InterfaceMethod{
virtual void method(void) = 0;
}
这是继承接口的类:
class ChildClass: public InterfaceMethod
{
public:
ChildClass(){}
~ ChildClass(){}
//virtual method implementation
void method(void)
{
//do stuff
}
//and this is the method that i want to use!
//a method declared in the child class
void anotherMethod()
{
//Do another stuff
}
private:
}
这是客户端:
int main()
{
InterfaceMethod * aClient= new ChildClass;
//tryng to access the child method
(ChildClass)(*aClient).anotherMethod();//This is nor allowed by the compiler!!!
}