Jump to content

Overriding virtual functions in parameterized classes


Erling

Recommended Posts

I have a problem with virtual functions being treated as if they were non-virtual in a parameterized class. Consider:

class MyComp #(type T) extends uvm_subscriber #(T);

  function new();
    super.new("", null);
  endfunction
  
  function void f();
    $display("%s", get_type_name());
  endfunction

  function void write(T t);
  endfunction
  
  function string get_type_name();
    return "MyComp#(T)";
  endfunction
  
endclass

class MyOtherComp extends MyComp #(int);

  function string get_type_name();
    return "MyOtherComp";
  endfunction

endclass
  
initial begin
  MyOtherComp c = new();
  c.f();
end

I had hoped this would print "MyOtherComp" since get_type_name() is virtual in uvm_object, but what's printed is "MyComp#(T)". Is this a bug or am I missing something obvious? The compiler is Questa 10.0d.

Erling

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...