470,849 Members | 1,361 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Vector of Pointers and push_back?

i have a problem with a vector of pointers.
i want to use push_back, and im doing it like this:

vector<Computer*> vcomputer;

Computer *check=new Mac(id,cpu,hdd,ram,monitor,all_in_one,sound,lan,dv d);

(Computer is my perent class, and mac inherit from him).

what is the right way to do it?

thank you!
Jun 9 '06 #1
1 3229
9,065 Expert Mod 8TB
That looks like an OK way to do it, what is going wrong.

As an alternitive rather than a vector of pointers you could actually have a vector of objects but your objects would have to have correct implementations for the copy constructor and assignment operator like so

Expand|Select|Wrap|Line Numbers
  1. vector<Computer> vcomputer;
  3. vcomputer.push_back(Mac(id,cpu,hdd,ram,monitor,all_in_one,sound,lan,dv d));
however the way have done it is not particularly wrong.
Jun 10 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by john smith | last post: by
9 posts views Thread by luigi | last post: by
14 posts views Thread by Roland Bengtsson | last post: by
9 posts views Thread by kathy | last post: by
8 posts views Thread by jagguy | last post: by
6 posts views Thread by Jia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.