STL static and moving multi-state

xiaoxiao2021-03-06  37

#include #include Using namespace std; / * If you need to implement <1>, pay attention to: 1. Define class base {

Virtual showdemo () const = 0;}; 2. Stripping abstract business is put into public class 3. Let Derived1, Derived2 inherit from BASE. 4. Subclas must implement interface functions <2> Take payment when using The parameters of the function can only use the base & or base * to pass the object address, so that it is found in the runtime discriminant type 2. Each inherits adds a virtual table to increase resource overhead. * / class derived1 {public: void showdemo () const {cout << "Derived1 :: showdemo ()" << endl;}};

Class deived2 {public: void showdemo () const {cout << "Derived2 :: showdemo ()" << endl;}};

// Use the template to interpret the solid-ginseng, the object type of the identified object directly in the runtime period / / only uses a generic, less than the SHOWDEMO, but it is actually instantified twice // because it is only for this whole The class uses a generic, but if the incoming T is other type / / static detection, it will find problems, discovery that the structure does not this function Template Void ShowdeMo (T const & t_g) {t_g.showdeMo ();}

Template Void Effeceach (T1 Const & T_g_1, T2 Const & T_g_2) {T_G_1.ShowdeMo (); T_G_2.ShowdeMo ();

Template Void ShowdeMoall (Vector const & t_v_g) {for (int i = 0; i

Void main () {

Derived1 t_d_1; derived2 t_d_2;

ShowDemo (T_D_2); showdemo (t_d_1);

Effeceach (t_d_1, t_d_2); Vector coll; coll.push_back (t_d_2); showdemoall (coll);}

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

New Post(0)