Jonathan, You can get what you want by creating a static method that call the constructor ('new' is already a special static method). class D1 extends Base; ... static function D1 knew; D1 = new(); endfunction endclass class D2 extends Base; ... static function D2 knew; D2 = new(); endfunction endclass Then this code will do what you want. b = D1::knew(); b.v(); b = D2::knew(); b.v(); This will work better than casting the constructor because it will be able to deal with the possible differences in arguments to the constructors of the derived classes. Dave -----Original Message----- From: owner-sv-ec@server.eda.org [mailto:owner-sv-ec@server.eda.org] On Behalf Of Jonathan Bromley Sent: Friday, August 03, 2007 8:51 AM To: sv-ec@server.eda-stds.org Subject: [sv-ec] Explicitly typed constructors? 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. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Fri Aug 3 12:45:53 2007
This archive was generated by hypermail 2.1.8 : Fri Aug 03 2007 - 12:46:05 PDT