Subject: Re: [sv-ec] Re: super and virtual func.
From: Arturo Salz (Arturo.Salz@synopsys.com)
Date: Wed Feb 12 2003 - 22:45:59 PST
Kevin,
Are you suggesting that super is restricted to work only
with virtual routines? There is no such restriction in the
LRM document. Super behaves exactly in the same
way as <parent_class>:: in C++. In fact, the SV version
of your example is:
--------------------------------------------------------------------------------
class foo;
virtual task whoami() $display( "foo" ); endtask
virtual task whoami2() $display( "foo" ); endtask
endclass
class bar extends foo;
virtual task whoami() $display( "foo" ); endtask
virtual task whoami2() super.whoami2(); endtask
endclass
task main;
bar bq = new;
bq.whoami();
bq.whoami2();
endtask
initial main;
--------------------------------------------------------------------------------
- gives -
bar
foo
You will note that whoami2 in class bar calls the virtual
function whoami2 in the parent class. If this call were
made as a virtual call, it would run as an infinite loop.
Explicit qualification of the class via super (or :: in C++)
always yields exactly that member (or property).
If this were not the case, it wouldn't be possible to
implement virtual destructors correctly in C++ (and
destructors should always be virtual).
Arturo
----- Original Message -----
From: "Kevin Cameron x3251" <Kevin.Cameron@nsc.com>
To: <sv-ec@eda.org>
Sent: Tuesday, February 11, 2003 1:18 PM
Subject: [sv-ec] Re: super and virtual func.
C++ does not have the restriction that routines used with
'::' should be virtual -
#include <stdio.h>
class foo {
public:
virtual void whoami() {printf("foo\n");};
virtual void whoami2() {printf("foo\n");};
};
class bar : public foo {
public:
virtual void whoami() {printf("bar\n");};
virtual void whoami2() {foo::whoami();};
};
void sub(foo *fp)
{
fp->whoami();
fp->whoami2();
}
main()
{
bar bq;
bq.whoami();
bq.foo::whoami();
bq.whoami2();
sub(&bq);
}
- gives -
bar
foo
foo
bar
foo
A call with :: is not a virtual call, it's handled the same
as a non-virtual call.
I.e. the restriction in SV doesn't have a precedent in C++.
Kev.
This archive was generated by hypermail 2b28 : Wed Feb 12 2003 - 23:16:35 PST