I'm moving from Objective-C to C++ and am not sure what vectors are. I've read documentation about them, I'm not quite clear though. How would you explain C++ vectors using Objective-C analogies?
They're pretty similar to NSMutableArrays
but vector
is a template class and so can be instanciated for any (standard-template-library compatible) type. NSArrays
always hold NSObjects
.
That is, assuming you mean std::vector
.
They're like NSMutableArrays but can hold any data type - pointer or not. However, each vector can only ever hold one type at a time. Also as it's C++ there are fewer functions e.g. no plist loading/saving.
A C++ vector (presumably you mean something like std::vector
) is basically an NSArray
, except it holds any type you want (which is the template parameter, e.g. a std::vector<int>
holds int
s). Of course, it doesn't do memory management (which NSArray
does), because arbitrary types aren't retain-counted. So for example a std::vector<id>
would be rather inappropriate (assuming Obj-C++).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With