[Fwd: ENHANCEMENT REQUEST:interpreted virtual function]

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Thu May 07 1998 - 19:05:08 MEST


This answer of Masa is of general interest.

-- Fons.

attached mail follows:


Dear Goetz, About virtual function resolution between interpreted and compiled classes, I understand what you mean, but to be precise simplified code you posted works properly. The problem happens when virtual function is called vir pointer to precompiled base class. // compiled.h class A { public: virtual void f() { /* something */ } } // interpreted.cxx class B : public A { public: void f() { /* something */ } }; main() { B b; b.f(); // calls B::f() A *p = new B; p->f(); // calls A::f() which is wrong } This is a known problem which is based on fundamental of C++. I've thought about this but there is no clean solution. Format of virtual table is compiler dependent and totally out of my control. But depending on your true needs, I could provide some workaround. For example, having dummy class _A as follows with STUB of concerned virtual function will give you correct result. // interpreted.cxx class _A : public A { public: virtual void f() { A::f(); } }; class B : public _A { public: void f() { /* something */ } }; main() { B b; b.f(); // calls B::f() _A *p = new B; p->f(); // calls B::f() } Masaharu Goto -------------------------- Dear Root developers, I have tried to derive a compiled class within a macro. That works fine except that still the virtual function of the base class is called and not the interpreted one of my derived class. I would like this feature regards, Goetz EXAMPLE: ======================================= Compiled class: ------------------ class A { public: A(void); virtual int do_something(void); void call_do_something(void); }; void A::call_do_somethin(void) { do_something(); } int A::do_something(void) { ... } ________________________________________________ interpreted: ------------------ class B : public A { public: B(void) : A() {}; int do_something(void); }; int B::do_something(void) { ... } int main() { B a_b; a_b.call_do_something(); } ------------------- if I start main() still A::do_something is called --------------------------------------------------------------- Goetz Gaycken, F-OPAL, @ DESY, 22603 Hamburg email: gfg@bolte.desy.de phone: +49 40 8998 3426



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:32 MET