Can you extend a concrete class into an abstract class?


A customer asked me whether you could extend a concrete class into an abstract class, by adding a pure virtual function.

It turns out you can. IEEE 1800-2012 section 8.21 confirms this:
Any class may be extended into an abstract class, and may provide additional or overridden pure virtual methods.
module M;
 
  virtual class pure_virtual_base_class;
    pure virtual function void foo;
  endclass
 
  class concrete_class extends pure_virtual_base_class;
    virtual function void foo; endfunction
  endclass
 
  virtual class another_pure_virtual_base_class extends concrete_class;
    pure virtual function void foofoo;
  endclass
    
endmodule

  
https://www.edaplayground.com/x/2FpZ

A customer asked me about this. I didn't know the answer, so I wrote a few lines of code on EDA Playground. EDA Playground is great for that, because it's always on. You don't have to queue for licences, wait for EDA tools to start, create new files, fire up editors...

Comments

Popular posts from this blog

Bit Width Casting in SystemVerilog

How to convert a std_logic_vector to a hex string?

Can you add/remove more than 1 item from a queue?