Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How much of C++ is supported in Objective-C++

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?

like image 500
rlbond Avatar asked Apr 11 '09 23:04

rlbond


People also ask

Is Objective-C compatible with C?

Objective-C is an object-oriented programming language that is a superset of C, as the name of the language might reveal. This means that any valid C program will compile with an Objective-C compiler. It derives all its non-object oriented syntax from C and its object oriented syntax from SmallTalk.

Is Objective-C supported?

While Objective-C is still supported by Apple and will likely not be deprecated anytime soon, there will be no updates to the language. Objective-C is as good as it's ever going to get.

Is Objective-C still used in 2022?

There are a lot of indicators telling us there's still a ton of legacy Objective-C code, both from Apple and from other developers, that's still in use.

Is Objective-C better than C?

Objective C can be called the super set of C language. It contains classes and objects in addition to C language. The pointers used in C language are vulnerable to security attacks. The language objective C uses null pointers and hence is type safe compared to C.


2 Answers

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.
like image 153
gavinb Avatar answered Sep 28 '22 03:09

gavinb


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.

like image 33
Zifre Avatar answered Sep 28 '22 05:09

Zifre