I'm just starting to learn C++, coming from a Java / bit of C background. I have some questions about how vectors of objects and pointers work in C++.
Say I want to create a vector of SomeClass objects, and the SomeClass constructor takes one argument. However, SomeClass is not copyable, so I can't do something like:
Expand|Select|Wrap|Line Numbers
- vector<SomeClass> someVector;
- for (int i=0; i<args.size(); i++){
- someVector.push_back( SomeClass(args[i]) )
- }
Expand|Select|Wrap|Line Numbers
- vector<SomeClass *> someVector;
- for (int i=0; i<args.size(); i++){
- SomeClass temp(args[i]);
- someVector.push_back(&temp);
- }
From general Googling, I get the feeling that in general, it's probably a good idea to get into the habit of storing pointers instead of actual objects and structs in vectors - so I should probably get used to using vectors of shared_ptr?
Also, any other general comments, tips, common gotchas, etc. will be greatly appreciated (trying to learn all I can!).
Thanks!