RE: [sv-bc] Can abstract class be instantiated?

From: Rich, Dave <Dave_Rich_at_.....>
Date: Mon Jul 23 2007 - 11:09:44 PDT
See mantis 1308 for clarification or section 8.20 in draft3

 

________________________________

From: owner-sv-bc@server.eda.org [mailto:owner-sv-bc@server.eda.org] On
Behalf Of Mike Mintz
Sent: Tuesday, July 17, 2007 6:01 AM
To: Surya Pratik Saha
Cc: sv-bc@eda-stds.org; sv-ac@eda-stds.org
Subject: Re: [sv-bc] Can abstract class be instantiated?

 

Hi Surya,

Sigh. This is SystemVerilog hiding the concept of pointers. When you
declare a variable of class type, you are really only declaring a
pointer. 

Even though BasePacket is abstract, it can still be used to declare a
variable: 
BasePacket packets[100];

This statement declares storage for 100 pointers. You cannot actually
build an instance of a BasePacket. The new() special member function
actually creates the instance of the class.

packets[0] = new BasePacket ();  <--Compiler error, cannot instiantiate
an abstract base class

So why is this useful? In one OOP technique, a base class can be used
when the details of the actual class are not relevant. For example, I
often make an array of "test irritators", which can be started, stopped,
and asked to report their status.  This is an abstract base class. I
then derive from test_irritator for general traffic generators, such as
usb_test_irritator and ethernet_test_irritator. Instances of these
derived classes are put into a pointer array of base classes because, by
design, my test is not concerned with the background traffic. The test
is testing some feature of the chip, but uses the background traffic to
stress the chip.

There are other uses of base classes as well. Contact me off list for
more info. (my name and trusster with a com.)

Hope this helps,
Mike


Take Care,
Mike

On 7/17/07, Surya Pratik Saha <spsaha@cal.interrasystems.com> wrote:

Hi,
As per 1800 LRM (section 7.19, page 93), an abstract class can not be
instantiated.
An abstract class cannot be instantiated; it can only be derived.

But later, in section 7.20, it is mentioned:
Even though BasePacket is abstract, it can still be used to declare a
variable: 
BasePacket packets[100];

What is the difference between an instance of a class and a variable
declaration of class?



-- 

Regards

Surya


-- 
This message has been scanned for viruses and 
dangerous content by MailScanner <http://www.mailscanner.info/> , and is

believed to be clean. 



-- 
This message has been scanned for viruses and 
dangerous content by MailScanner <http://www.mailscanner.info/> , and is

believed to be clean. 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Mon Jul 23 11:10:25 2007

This archive was generated by hypermail 2.1.8 : Mon Jul 23 2007 - 11:11:04 PDT