c++ - Can I cast std::vector<Animal*> to std::vector<Dog*> without looking at each element? -


I have a base class in which several squares have been expanded. I have some generic library utilities that make a vector-oriented pointers for the base class so that any of the sub-squares work, how can I remove all elements of vector to a particular child class?

  // A method is said to be believed that animals with dogs thrown in animals are passed. Zero myDogCallback (Vector & Lt; Animals * & gt; and Animals) {// I have all the elements of animals / vectors & lt; Dog * & gt; Dogs = Artists (Animals); }  

My inexperienced solution will look something like this:

  // A method is said to be believed that a vector in which the animal is planted The dogs are gone by the passage. Zero myDogCallback (Vector & Lt; Animals * & gt; and Animals) {// I have all the elements of animals / vectors & lt; Dog * & gt; Dog's; Vector & lt; Animals * & gt; :: Iterator Eater; (Iter = animals.begin (); iter! = Animals.end (); ++ iter) {dogs.push_back (dynamic_costs  

using std :: transform You can. It internally uses () for , but you will get two-string implementation:

  #include & lt; Vector> #include & lt; Using Algorithm> Namespace std; Structure animal {virtual ~ animal () {}}; Struct dog: Animals {dog} (dog) {}}; Template & lt; Typename Goal> Structure Animal2Target {target * operator () (animal * value) const {return dynamic_cast & gt; Goal *> (value); }}; Zero myDogCallback (vector & lt; animal *> and animals) {{Vector & lt; Dogs * dogs; Conv. (Animals. BGIN), animals. (), Dogs (), animal 2 targets & amp ;; Dogs> ()); }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -