Jonathan, Evidently, the simulator used by the student has a bug. He should see "3" and "4", as expected. BTW, only virtual methods truly override methods in base classes. All other methods and properties do not override but provide name hiding. Hence, in your example, class D has two properties called "N" and two methods called "get_N", one in class D proper and one in its super class (class C), each one is accessible via an object handle of the corresponding type. Only from the perspective of class D is the property overridden. If you had declared a virtual method Boo in class C and in class D then an object of type D would have only one method implementation - that of class D, regardless of the object pointer used. class C; int N = 3; function int get_N(); return N; endfunction virtual function int Boo(); return 5; endfunction endclass class D extends C; int N = 4; function int get_N(); return N; endfunction function int get_N1(); return super.N; endfunction virtual function int Boo(); return 6; endfunction endclass ... ... D d = new; C c = d; // Note same object! $display(c.get_N()); // "3" $display(d.get_N()); // "4" $display(d.get_N1()); // "3" - super.N $display(c.Boo()); // "6" $display(d.Boo()); // "6" c = new; $display(c.Boo()); // "5" Arturo -----Original Message----- From: owner-sv-ec@eda.org [mailto:owner-sv-ec@eda.org] On Behalf Of Jonathan Bromley Sent: Friday, October 19, 2007 7:15 AM To: sv-ec@eda.org Subject: [sv-ec] Prohibit overriding data members of a class? hi EC, I recently had a query from a student who had tried to override a *data* member of a class... class C; int N = 3; function int get_N(); return N; endfunction endclass class D extends C; int N = 4; function int get_N(); return N; endfunction endclass ... ... D d = new; C c = new; $display(c.get_N()); // "3" as expected $display(d.get_N()); // "3" seen ???!!! (By the way, I don't even know which simulator this person was using.) It seems to me that this should be illegal, and you should be able to override only methods, not data members. Although the LRM hints as much, I can't find an explicit prohibition of overriding a data member, nor a description of what to do should it occur. Any other opinions? Is this just a compiler failing to report an error, or have I missed something? Do we need some minor LRM clarification for this? -- 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 Oct 19 10:50:48 2007
This archive was generated by hypermail 2.1.8 : Fri Oct 19 2007 - 10:51:13 PDT