Advanced Techniques Guide 08-SV object-oriented programming

1, and extended by the original class

  (1) The original class is called the parent class or superclass, extended class is called a derived class, or subclass. Extension class can directly access the original class of its own and all variables should be defined subroutines in the original class into a virtual, so that they can redefine the extended class. new function can not be extended, SV always based on the type of handle to call the new function.

  (2) extended class constructor

    If the base class constructor has parameters, extended class must have a constructor and a constructor must call the base line of a first class in its constructor.

  (3) on the handle

    A base class (Transaction) can also be used to handle point to a derived class objects (BadTr) a. When calling tr.calc_crc function, in the end it is to call the base class virtual function call or extended class in extended calc_crc, depending on the type of object tr: if the object is Transaction type, then call the Transaction :: calc_crc, otherwise, call BadTr :: calc_crc

  

Guess you like

Origin www.cnblogs.com/wt-seu/p/12297170.html