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 Console base function returns the message: You can use 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".
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 ());}};
int main (int argc, char * Argv []) {CZoo nationalPark; nationalPark.addDog ();. NationalPark.animalList.front () soundsLike (); // base function call return 0;}
of std :: vector & lt; std :: unique_ptr & lt; CAnimal & Gt; & gt; Zoo; Zoo.push_back (new cdig) ); Zoo [0] -> soundsLike ();
Comments
Post a Comment