CQM
CQM

Reputation: 44200

Objective C with some C++ code won't compile

I have an Objective C project with some C++ code, and sure enough the C++ code won't compile

I understand that the compiler makes assumptions about which language to compile, but I have seen this app running before so I am curious how to make my Xcode 4 run compile this project

ie. This function declaration produces an error as the compiler does not recognize the c++ std:: syntax

 std::string string_with_formatting(const unsigned int value)
 {

How do I get around this? What #include or #import should I have

Upvotes: 8

Views: 3957

Answers (3)

Dair
Dair

Reputation: 16240

Change that file to .mm and also any other that includes that file (or that files accompanying .h).

Upvotes: 0

hamstergene
hamstergene

Reputation: 24429

Objective-C++ is a superset of C++. You can use C++ in Objective-C++ sources.

  1. Make sure the file has .mm extension, otherwise it will be treated as Obj-C, not Obj-C++
  2. #include <string>

Upvotes: 10

Foo Bah
Foo Bah

Reputation: 26251

objective C has no concept of std::string. You need to use something like NSString

Upvotes: -1

Related Questions