Can I use STL and C++ in ithe iPhone?

Member
Posts: 249
Joined: 2008.10
Post: #1
Hi all!

I know is possible to use C++ developing a game for the iPhone (under xcode)

My question is: is Standard Template Library available? and can I use Unicode?


Thanks.
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2008.08
Post: #2
Yes, the STL is available.

Not sure about unicode, I'd imagine so, but haven't tried so can't say for sure.
Quote this message in a reply
Member
Posts: 32
Joined: 2008.10
Post: #3
Yes, STL is available (my engine uses it heavily).
I'm not using the native Cocoa libraries, I'm using freetype, so yes, Unicode is possible.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #4
I was just thinking about this because I sure do need a lot of the STL functionality. Curious, how do you go about using STL? It's not as simple as just including it because of the way Obj-C interprets the < > brackets. What's the trick?

Also, #include <vector.h> or #include <vector> caused an error. Where is it located?

I would sure like to know how to use a templated C++ class. I have a linked list that would be very useful in my game.
Quote this message in a reply
Member
Posts: 32
Joined: 2008.10
Post: #5
bmantzey Wrote:I was just thinking about this because I sure do need a lot of the STL functionality. Curious, how do you go about using STL? It's not as simple as just including it because of the way Obj-C interprets the < > brackets. What's the trick?

The compiler looks at the file extension. If it's .cpp, it will use the standard gcc compiler. Everything works exactly the same as C++ only environments.

If you are mixing obj-c code and C++, rename the files with obj-c code to .mm. The compiler will be smart enought to know the difference between [NSilb method] and std::stl methods.

Thats all there is to it.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
It's not *quite* all there is to it. Including a C++ object by value in an ObjC class doesn't work the way you want by default. There's a compiler option which tries, or you can use "placement" new yourself, or (frequently easier) only put C++ objects in ObjC classes by pointer.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #7
smallstepforman Wrote:The compiler looks at the file extension. If it's .cpp, it will use the standard gcc compiler. Everything works exactly the same as C++ only environments.

If you are mixing obj-c code and C++, rename the files with obj-c code to .mm. The compiler will be smart enought to know the difference between [NSilb method] and std::stl methods.

Thats all there is to it.

Excellent! Thank you!
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #8
I am at the point now where I need to use this template class I wrote. It's a circular linked list, which is really the most optimal way to achieve what I need. It needs to be a linked list and I don't think NSArray objects will work because there will be situations where an element in the list will change, and it will then need to follow that branch.

Anyway, the compiler does not like including a .h that is a templated class. I tried changing it to .mm and it liked that even less. How do I get a templated class into my project?

Edit: I think I may be on my way to figuring this out. I'm not getting the bunch of errors as I was before but now I am getting a lot of warnings regarding the constructor and destructor. Apparently, they constructor and destructors are not called if they are user defined?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
read up a couple posts Wink
Quote this message in a reply
Post Reply