Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Objective C NSMutableArray Equivalence

This topic is 2799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Hi,
I finally realized that it was doing some memory allocation then initialization of the object. Thanks for participating in the help!
Jack

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!