C ++ ordinary overload, virtual function overload, pure virtual function overload

xiaoxiao2021-03-06  42

I don't know much about these three types of overloads in the first few times. There are some mixes.

Today, I made such an example to test a few functions.

different.

Base class: class a {public: a (); void f1 (); Virtual Void F2 (); Virtual Void F3 () = 0; Virtual ~ A ();

}

Subcrete: Class B: Public a {public: b (); Void F1 (); Void F2 (); Void F3 (); Virtual ~ b ();

}; Main function: int main (int Argc, char * argv []) {a * m_j = new b (); m_j-> f1 (); m_j-> f2 (); m_j-> f3 (); delete m_j Return 0;}

F1 () is an ordinary overload. Call m_j-> f1 (); will call F1 () in the Class A class, it will be customized when we write the code. That is, according to A Class definition, then call this class function. F2 () is a virtual function. Call m_j-> f2 (); call M_J in the object saved in the M_J, the corresponding function. This is due to the NEW B object. F3 () is the same as F2 (), but does not need to write a function in the base class.

转载请注明原文地址:https://www.9cbs.com/read-54967.html

New Post(0)