LHS of super.new() && Passing Handle as Input VS ref

Hello Everyone ,

I am confused regarding calls to Base Class constructor from an Extended Class Constructor .

Normally when we call a Constructor the LHS is seen as to whose constructor needs to be Called .

(I) what about the LHS of super.new() ? . Since there is No return type in a Constructor , we don’t a warning when there is no left hand side of super.new()

Passing an object handle to a method as ref argument VS as an input argument


when handle is passed as ref the address of the variable is passed so that modifications made inside the method are reflected back.

(II) what happens when its passed as an input argument . what gets passed to the method ? Since we can access the objects properties inside the method , but when the properties or Object is modified the change isn’t reflected back ?

I have following lines from a deep copy function ::

// In extended Class Ext


virtual function Base copy ( input Base b1 = null); // Signature Same as Base Class virtual copy function
Ext e1 ; // Ext is extended class

if ( b1 == null )
   e1 = new();
else
  $cast(e1,b1); // Downcasting else I would compilation error 

super.copy(e1) ; // (a)
// Assign extended class property
e1.new_property = this.new_property ;

return e1 ; // returned type is different that the function prototype

(III) In statement (a) I get a warning of Implicit void cast. What should be the LHS during call to super.copy() ?

(IV) How would the above extended class method be called from outside the class ?

**(V)return type of method is Base whereas we actually return ext type object . So is it necessary to use downcast during call to extended class copy function ?
**

Thanks in advance ,
HV

In reply to himanshu valecha:

“new” is a reserved keyword and has syntax slightly different from calling a typical class method. When new appears on the RHS of =, the return type is implicitly the class type of the variable on the LHS. The statement super.new() is chaining the procedural code in each constructor; it is not constructing another object. There is only one extended object.

Please see this recent post about ref arguments and class handles.

It would be much easier to separate copy functionality from construction. See my article that shows the clone() method.

In reply to dave_59:

Hello Dave ,

Thank you for your reply .

Could you please elaborate on your statement "The statement super.new() is chaining the procedural code in each constructor " .

Thanks in advance ,
Himanshu V

In reply to himanshu valecha:

Can you read section
8.17 Chaining constructors
in the 1800-2017 LRM?

Also suggest taking my class on classes

https://www.edn.com/design/systems-design/4461407/Inheritance-and-polymorphism-of-SystemVerilog-OOP-for-UVM-verification?utm_source=Aspencore&utm_medium=EDN&utm_campaign=social