iPhone objective-c and c++

if you want to use c++ files in your iphone app do this:

  1. rename the FILE.m in FILE.mm
  2. import the .cpp class


#import "Foo.cpp"
- (void)aFunction:()
 Foo foo = *(new Foo(123));
 NSString *objcString =
[NSString stringWithUTF8String:foo.testStr.c_str()];
 NSLog(@"string test: %@", objcString);
 NSLog(@"foo id start: %i", foo.myId);
 NSLog(@"foo id: %i", foo.myId);

foo class

#include <string>
class Foo
 public : int myId;
 public : std::string testStr;
 public : Foo(int startVal)
 testStr = "Hallo Welt21212! äöü ß";
 myId = startVal;
 public : void setId(int newId)
 myId = newId;
 public : void test()


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">