Re: [sv-bc] Question on pure virtual function

From: Gordon Vreugdenhil <gordonv_at_.....>
Date: Tue Oct 07 2008 - 07:04:31 PDT
Surya, you are assuming (incorrectly) that SV works in the
same manner as C++ in *inferring* the "abstract" aspect of
the class.  That isn't the case.  Even in the quote that
you give, the text says "...the subclass needs to be abstract."

The LRM is clear that the only way to define an abstract class
is by saying "virtual class" so it follows that "virtual class"
is required in the derived class as well as the base.

This redundancy is, in my opinion, a good thing since it ensures
that the expected abstract/non-abstract state of the class can
be checked by the *type* specification alone as opposed to having
to wait until one sees a "new" before flagging the error.

Gord



Surya Pratik Saha wrote:
> Hi,
> Though I don't have the access to draft LRM, but by reading the SV 
> mails, I came to know SV 2009 is going to support something called pure 
> virtual function inside class similar to C++ (i.e. there will no body 
> for the virtual function which is declared with 'pure' keyword). And 
> also there is a LRM snippet :
> *In general, if an abstract class has any virtual methods, all
> of the methods must be overridden (and provided with a method body) for 
> the subclass to be instantiated. If any virtual methods have no 
> implementation, the subclass needs to be abstract.
> 
> *So if we go by LRM, then any subclasses which does not have any body 
> for the pure virtual function present in the base class, then that sub 
> class too will be considered as abstract, i.e. this is also not allowed 
> to be instantiated.
> 
> Now, except one standard simulator, none yet support pure virtual 
> function. And if we consider the following case:
> 
> virtual class base;
>     pure virtual function int f();
> endclass
> 
> class derived extends base;
> endclass
> 
> That simulator fails saying that the pure virtual function is not 
> defined inside 'derived' class. I think this is an incorrect behaviour, 
> as SV LRM as well as C++ LRM does not mention to give error, they mean 
> just the class 'derived' then becomes abstract (can not be 
> instantiated). And if we derive another class from this subclass where 
> the body of the pure virtual function is there, then it should be fine.
> 
> So the simulator must have a bug. Please can anyone comment on that.
> -- 
> 
> Regards
> Surya
> 
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.

-- 
--------------------------------------------------------------------
Gordon Vreugdenhil                                503-685-0808
Model Technology (Mentor Graphics)                gordonv@model.com


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Oct 7 07:08:17 2008

This archive was generated by hypermail 2.1.8 : Tue Oct 07 2008 - 07:09:21 PDT