Skip to main content

Posts

Showing posts from November, 2012

C++ class in Objective-c Code

Add a new file to the project, and instead of selecting the iphone stuff, select the mac osx stuff under it. In that select “C and C++” then add a C++ file, call it “Math”. Define a very simple class: class  Math { private : public : int  addNumbers( int  num1,  int  num2); }; Then in the .cpp file add this: #include  “Math.h” int   Math ::addNumbers( int  num1,  int  num2){ int  total =  0 ; total = num1 + num2; return  total; } If you can’t figure out by now we are making a class that adds two numbers. Now import the math class into your .h file of the view controller, and then in the implementation add this to the “view did load” function - ( void )viewDidLoad { Math  tempMath; int  tempNum = tempMath. addNumbers ( 15 ,  10 ); NSString  *tempString = [[ NSString   alloc ]  initWithFormat : @”%i” ,  tem...