[Fwd: ENHANCEMENT REQUEST:interpreted virtual function]

Fons Rademakers (Fons.Rademakers@cern.ch)
Thu, 07 May 1998 19:05:08 +0200


This is a multi-part message in MIME format.
--------------F5A74F8D2C337B8C0583A8B9
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This answer of Masa is of general interest.

-- Fons.
--------------F5A74F8D2C337B8C0583A8B9
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Return-Path: <MXJ02154@niftyserve.or.jp>
Received: from dxmint.cern.ch (dxmint.cern.ch [137.138.26.76])
by pcsalo.cern.ch (8.8.7/8.8.7) with ESMTP id OAA02096
for <rdm@pcsalo.cern.ch>; Thu, 7 May 1998 14:55:38 +0200
Received: from hpsalo.cern.ch (hpsalo.cern.ch [137.138.199.59]) by dxmint.cern.ch
with ESMTP id OAA00538; Thu, 7 May 1998 14:55:38 +0200 (MET DST)
Received: from dxmint.cern.ch (dxmint.cern.ch [137.138.26.76]) by hpsalo.cern.ch with ESMTP (8.7.1/8.7.1) id OAA17621 for <rootdev@hpsalo.cern.ch>; Thu, 7 May 1998 14:29:59 +0200 (METDST)
Received: from ms7.niftyserve.or.jp (ms7.niftyserve.or.jp [192.47.24.147]) by dxmint.cern.ch
with ESMTP id OAA32455 for <rootdev@hpsalo.cern.ch>; Thu, 7 May 1998 14:29:54 +0200 (MET DST)
Received: (from root@localhost) by ms7.niftyserve.or.jp (8.8.8+2.7Wbeta7/3.5Wpl1-970106) id VAA14197; Thu, 7 May 1998 21:29:48 +0900 (JST)
Message-Id: <199805071229.VAA14197@ms7.niftyserve.or.jp>
Date: Thu, 07 May 1998 21:28:00 +0900
From: Masaharu Goto <MXJ02154@niftyserve.or.jp>
Subject: RE:ENHANCEMENT REQUEST:interpreted virtu
To: rootdev@hpsalo.cern.ch

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

--------------F5A74F8D2C337B8C0583A8B9--