c++ - Dynamic Polymorphism and Dynamic Memory Allocation -


Is it always necessary to allocate memory to the map for the convenience of dynamic polymorphism? All the examples I have come so far for the same thing. Dynamic memory allocation is usually avoided with real-time programming. Therefore, there is no harm to using the stack for dynamic polymorphism as shown in the code below. public: virtual void display () = 0; }; Category received: public base {public: zero performance () {cout & lt; & Lt; "Derivative" & lt; & Lt; Endl; }}; Int main () {base * base; Derivative Derivative 1; Base = & amp; Derived1; Base- & gt; Fu (); Return 0; }

A better example would be:

  zero Funk (base and base); Int main () {Derivative Derivatives; Ceremony (derivative); Return 0; }  

The use of polymorphism should not be close to the creation of objects on stacks.

Most of our unit testing codes are seen these days roughly:

  zero trials () {mock object mock obj; Real Object Object Touched (Mock Oz); // test}  

It depends well on polymorphism, but creates objects on the stack.


Comments