c++ - Code selector using inheritage during runtime -


Is there a way to insert an abstract class inside a container? No. Is there a way for a base class to reach derivative classes? Using the Virtual Function
Is this example code any way to work properly and bark to console? Is there any way for vector containers? Do not keep examples, do not keep reference / notation? It is safe to store points inside std :: vector if I use reference counters in examples, which is my last resort, do I miss something?

  class cnimal {public: like virtual zero sounds () {cout & lt; & Lt; "Base function \ n"; }}; Class Cadence: Public Cannmil {Public: Zero Sounds (like) (cout & lt; & lt; "vap \ n";}}; Class CZoo {public: std :: vector & lt; cnimal & gt; animalList; Add zero () (AnimalList.push_back (CDog ());}};   

Console base function returns the message:

  int main (int argc, char * Argv []) {CZoo nationalPark; nationalPark.addDog ();. NationalPark.animalList.front () soundsLike (); // base function call return 0;}    

You can use

  of std :: vector & lt; std :: unique_ptr & lt; CAnimal & Gt; & gt; Zoo; Zoo.push_back (new cdig) ); Zoo [0] -> soundsLike ();   

Is this bad? Unique logos will handle destruction for you.

I do not think you Besides the references, I do not think you can make it "bark." Only "woof".

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -