RE: [sv-ec] Virtual function call from base class constructor

From: Daniel Mlynek <daniel.mlynek_at_.....>
Date: Wed Jun 25 2008 - 10:58:46 PDT
>This is rather self-evidently sensible,
Not true. Language should define the behaviour  - there are pros and cons of
each solution  - take a look into below link ( it work exactly opposite in
both C++ and C#:)

http://blogs.msdn.com/abhinaba/archive/2006/02/28/540357.aspx

Sure that this construct should be be avoided - but anyway this have to be
defined.


DANiel 

-----Original Message-----
From: Jonathan Bromley [mailto:jonathan.bromley@doulos.com] 
Sent: Wednesday, June 25, 2008 7:41 PM
To: Gordon Vreugdenhil; Chris Spear
Cc: Daniel Mlynek; sv-ec@server.eda.org
Subject: RE: [sv-ec] Virtual function call from base class constructor

[Gord]

> During construction, you cannot safely call an overridden method since 
> the derived class state would not have been initialized yet.  As with 
> C++ (ISO C++ 1998, Sec 12.7), SV should clarify that during 
> construction you effectively change your vtbl as construction 
> progresses so that you only get "the most derived" override vis-a-vis 
> the type of "new"
> that you are currently executing.

This is rather self-evidently sensible, but current tools are not unanimous
about it; currently I count one in Gord's favour, two in Chris's.  At
present I recommend to people that they should completely avoid calling
virtual methods from a constructor.

While we're thinking about constructors, can I raise something I've been
meaning to ask for ages?  The constructor is, in many respects, a static
method.  If new() could be treated truly as a static method, then we could
get this rather convenient idiom:

  class C;...
  class D extends C; ...
  ...
  C c;
  c = D::new();

Is there any fundamental problem with this that I've missed?
--
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

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 Wed Jun 25 10:59:41 2008

This archive was generated by hypermail 2.1.8 : Wed Jun 25 2008 - 10:59:50 PDT