c++ - Is it possible to create a vector of pointers? -


Just wondering, due to a problem I am running, is it possible to make vector of indicators? And if so, how? Specifically about iterators and using .begin () with it, i.e.: how will I change this vector into a vector of pointers:

  class c {void virtual func (); }; Class Scale: Public C {Unfollow function (cout  fancy ();}  

Sure.

  vector  cvect; Cvect .push_back (new SC); vector & lt; c * for :: Iterator seater; citer = cvect.begin (); sever! = Cvect.end (); citer ++) {(* citer) -> Func ();}  

To keep things in mind:

If you have dynamic allocated memos If you use RE, you will need cleaning after your own as I did in my example

Example:

 For  (...) { Delete * i;}  

It can be simplified using a vector of shared_ptr s (like boost :: shared_ptr ) Do not try to use std :: auto_ptr for it, it will not work (will not be compiled).

To keep one thing in mind, you must & lt; To compare iterators in your loop whenever possible, it will only work for iterators which is a random access itater model, which means that you can not change your code for example using a < Code> std :: list .


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -