[sv-ec] Explicitly typed constructors?

From: Jonathan Bromley <jonathan.bromley_at_.....>
Date: Fri Aug 03 2007 - 08:51:07 PDT
hi sv-ec,

In some recent work I've frequently encountered the situation
that I have a variable of base class type, but wish to be
able to construct objects of various derived types and use 
the common base variable to reference them.  To construct the 
derived objects, I need a derived-type variable (don't I?):

  class Base; 
    .... 
    virtual function void v(); ...
    ....
  endclass : Base
  class D1 extends Base; .... endclass
  class D2 extends Base; .... endclass
  ....
  Base b;
  D1 d1;
  D2 d2;
  ....
  d1 = new;
  b = d1;
  b.v();
  ....
  d2 = new;
  b = d2;
  b.v();

It would be very nice if I could force new() to create 
an object of a derived-class type even though the result 
of new() is then assigned immediately to a base-class 
variable: something like

  b = D1::new();
  b.v();
  b = D2::new(); 
  b.v();

Or, maybe,

  b = D1'new();

Either way, the idea is to mirror Java's

  b = new D1();

Has this already been dismissed for some reason?
I'm no OOP guru, but I can't see any killer reason
why it should be unreasonable.

Thanks
-- 
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223                   Email: jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573                           Web: http://www.doulos.com

The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Aug 3 08:51:31 2007

This archive was generated by hypermail 2.1.8 : Fri Aug 03 2007 - 08:51:59 PDT