Objective C NSMutableArray Equivalence

Started by
8 comments, last by Captain P 13 years, 5 months ago
Does anyone have any idea of what Objective C NSMutableArray corresponding data type is in Visual C++?
Thanks
Jack
Advertisement
Probably the closest equivalent would be std::vector. However, keep in mind that Objective C and C++ are very different languages, and the correspondence is far from 1:1.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Quote:Original post by ApochPiQ
Probably the closest equivalent would be std::vector. However, keep in mind that Objective C and C++ are very different languages, and the correspondence is far from 1:1.


Thanks... I shall take a deeper look at that.
Jack
Hi, I am back

I wonder how to convert the following statement into C++?

[self setPathAssessment:[[[ASISpatialPathAssessor alloc] initWithMap:map] autorelease]];

It's in objective C
Thanks
Jack
There is no equivalent in standard C++. It sounds like you want to use a library.
Hi rip-off,
Thanks for your reply. If there is no equivalent for this statement, could you, at your convenience, explain what this code does? because I am porting an objective c project to Visual C++ and I came across a lot of troubles.
Thanks a lot
Jack

Hi,
I finally realized that it was doing some memory allocation then initialization of the object. Thanks for participating in the help!
Jack
NSMutableArray can hold any object type so it's similar to std::vector<Base*> where all your objects inherit from Base. You can then use the typeid operator for roughly the same functionality as Objective C offers. There's also boost::any, but I think it operates on value types, which is fundamentally different to the way Objective c handles objects.
Thanks!!! :)
Note that NSArray's and NSMutableArray's are often used with a single type only, so you most likely won't need a fancy solution for that in C++. If you have a NSMutableArray that only ever contains NSString*'s, a std::vector<std::string> (or std::wstring) is just fine.


Also, the two languages are significantly different that a 1:1 translation is not going to give the best results. One thing would be memory management - Objective C uses a retain count system, accompanied by autorelease pools. In C++, the most similar to that are probably shared pointers, but you can also take advantage of the stack and things like RAII. Another thing would be Objective C's messaging system. C++ does not have something like that built-in, so if your project depends on that, you may need to find an alternative solution in C++.
Create-ivity - a game development blog Mouseover for more information.

This topic is closed to new replies.

Advertisement