I want to make an iPhone app, but I am planning to make the framework in C++. Is it possible to use things like templates in Objective-C++. I guess really the question is, can I use boost?
All of C++ is supported in Objective C++. It should be possible to use boost, but you might have to port some of the platform dependant things.
Objective C++ is a superset of C++. Everything that you can do in C/C++ can be done in Obj-C++. The "Objective" portion contains, among other things, a Smalltalk-esque messaging system and other additions to C++.
It should be pointed out that you can't just do everything that you can do in C++ in Objective-C++. For example you can't call virtual functions on C++ objects from an Objective-C class. Once you call into a C/C++ function you can do whatever you want though.
C++ objects in Objective C will NOT necessarily act like in C++. For example constructors and destructors are not automatically called and (i think) that you can't implement virtual methods...
Is it possible to use things like templates in Objective-C++.
Yes, but you need to take care how you mix types and interfaces between the pure C++ layers and the Objective-C++ code. Keep in mind the boundaries between layers, where you would need to convert types such as std::string
to NSString
, and so on.
For example, you could implement the core game engine in pure C++, and just implement your controllers and GUI code in Objective-C++. Then the Obj-C++ code is the glue between the pure C++ engine and Cocoa.
I guess really the question is, can I use boost?
Given the iPhone OS is a subset of OS X that still provides a full POSIX layer, most Boost libraries should work just fine. It should be just like writing Darwin code.
There are a number of limitations in Objective-C++ to be aware of (taken directly from the Objective-C 2.0 Reference Guide):
- you cannot use Objective-C syntax to call a C++ object
- you cannot add constructors or destructors to an Objective-C object
- you cannot use the keywords this and self interchangeably
- the class hierarchies are separate; a C++ class cannot inherit from an Objective-C class, and an Objective-C class cannot inherit from a C++ class
- an exception thrown in Objective-C code cannot be caught in C++ code and, conversely, an exception thrown in C++ code cannot be caught in Objective-C code.
Boost is useful but it is also a large overhead to add to a project.
Make sure you really need it before you go adding it.
For Regex support: RegexLite.
For everything else: Cocoa.