171

What is Objective C++ and can I use this language in Xcode?

5
  • The close reason 'difficult to tell what is being asked' was an older reason for closing a question. These days the reason would be 'too broad' as the OP is really two different questions. First, explaining Objective C++ would take several pages to address, and second, coding for iOS is specifically done using Objective C and XCode is the default IDE for iOS development so even though the two are related it is too large a question itself. These type of questions should be moved to the Documentation site. – Kelly S. French Jul 11 '17 at 13:42
  • 2
    @DaveVoyles-MSFT: I am having a hard time taking someone seriously who thinks that downvoting a question and the mechanized, industrialized, organized, systematic mass murder of over 6 million people are the same thing. – Jörg W Mittag Feb 3 '18 at 13:02
  • 5
    @JörgWMittag I'm sorry, but you're response has been closed as not a real question by Stack Overflow moderators. – Dave Voyles Feb 4 '18 at 16:38
  • 1
    @DaveVoyles-MSFT: The "not a real question" close vote reason was removed years ago. – Jörg W Mittag Feb 4 '18 at 19:06
  • 1
    Closing reason is not a real reason and is difficult to tell what was the matter with downvoters. This reason is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably explained in its current form. – fledglingCoder Jul 25 '19 at 13:55
169

Objective-C++ is simply source code that mixes Objective-C classes and C++ classes (two entirely unrelated entities). Your C++ code will work, just as before, and the resulting executable will be linked with the Objective-C runtime, so your Objective-C classes will work as well. You can definitely use it in Xcode -- name your files with the .mm extension.

Also, you might want to read Apple's (sadly deleted, but archived) documentation on Objective-C++.

1
  • 3
    the limitation section in that link says this and is worth quoting Objective-C++ does not add C++ features to Objective-C classes, nor does it add Objective-C features to C++ classes. For example, you cannot use Objective-C syntax to call a C++ object, you cannot add constructors or destructors to an Objective-C object, and 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. In addition, multi-language exception handling is not supported – asgs Dec 31 '19 at 8:08
35

Objective-C++ is Objective-C (probably with Cocoa Framework) with the ability to link with C++ code (probable classes).

Yes, you can use this language in Xcode to develop for Mac OS X, iPhone/iPodTouch, iPad. It works very well.

You don't have to do anything weird in your project to use Objective-C++. Just name your Objective-C files with the extension .mm (instead of .m) and you are good to go.

It is my favorite architecture: develop base class library of my game/application in C++ so I can reuse it in other platforms (Windows, Linux) and use Cocoa just for the iPhone/iPad UI specific stuff.

1
  • 11
    Its not about linking with C++ - did you mean mixing? – Georg Fritzsche Sep 10 '10 at 13:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.