Chris, I disagree. 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. So, in your example, the call to "t" in A::new should *always* call A::t since that is "the most derived" at that point of the call to A::new whereas the call to "t" in A::f should call either A::t or B::t depending on the actual object type. Gord. Chris Spear wrote: > Daniel, > > > > The calls to t() are actually this::t(), so it makes sense that you > always get the extended function. Even when you call the constructor for > class A, the handle is of type B, so this::t() expands into B::t(). > Here is a more complete example: > > > > class A; > > virtual function t; > > $display("base class A"); > > endfunction > > > > function new; > > $display("In %m"); > > t(); // This should call A::t or B::t because t() is virtual > > f(); > > endfunction > > > > function f(); > > $display("In %m"); > > t(); // This should call A::t or B::t because t() is virtual > > endfunction > > endclass > > > > class B extends A; > > virtual function t; > > $display("Extended class B"); > > endfunction > > > > function f(); > > $display("In %m"); > > t(); // this should call B::t bacause t is virtual > > endfunction > > endclass > > > > module top; > > > > initial begin > > A a; > > B b; > > $display("\nConstructing A"); > > a = new; > > $display("\nCalling a.f()"); > > a.f(); > > $display("\nCalling a.t()"); > > a.t(); > > > > $display("\nConstructing B"); > > b = new; > > $display("\nCalling b.f()"); > > b.f(); > > $display("\nCalling b.t()"); > > b.t(); > > end > > endmodule > > > > /********************************************************* > Chris Spear Verification Specialist > Synopsys, Inc. Phone 508-263-8114 .. __@ > 377 Simarano Drive Fax 508-263-8123 _`\<,_ > Marlboro, MA 01752 USA Cell 508-254-7223 .. (*)/ (*) > Spear_ f rom _Synopsys.com http://Chris.Spear.net/systemverilog > <http://chris.spear.net/systemverilog> > Just released: new edition of "SystemVerilog for Verification" > *********************************************************/ > > > > > -- > 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 Wed Jun 25 07:01:29 2008
This archive was generated by hypermail 2.1.8 : Wed Jun 25 2008 - 07:01:59 PDT