How to call an abstract class method if there is only a pointer to a class, of which I only know that one of its parents is this abstract class?
class A { virtual void Init()=0; }; class B { public: int i; B() : i(0) {}; }; class C : public A, B { public: int i; C() : A(), B() {}; void Init() {}; }; class D : public A { public: int i; D() : A() {}; void Init() {}; }; // представим что тут нельзя написать A вместо void void func(void* ptr); int main() { C obj1; D obj2; func((void*)&obj1); func((void*)&obj2); return 0; } void func(void* ptr) { // так конечно работает, // но как то это не красиво, хотя бы по отношению к D ((C*)ptr)->Init(); }
upd: Thank you all for participating, the answer ((A*)ptr)->Init();
of course it is obvious, inattention was let down as always, my problem lay in the fact that multiple inheritance does not really work with builder VCL, that is, if C and D are VCL classes, then ((A*)ptr)->Init();
will not work, harsh reality (((