how to build c++ file and create its instance in another objective-c class
how to build c++ file and create its instance in another objective-c class
- Subject: how to build c++ file and create its instance in another objective-c class
- From: "Tang Ke" <email@hidden>
- Date: Fri, 6 Jun 2008 15:53:44 +0100
Hi,
I'm new to iphone os programming and my project involves to build c++ files
within the xcode cocoa touch environment.
So i tried to create a new cocoa touch project and use the interface builder
to add a button and a label.
So that when i press the button, the label would show the result of the
"add()" method i call from the following c++ file.
I then add a new c++ file called Adder.cpp which looks like this:
class Adder{
public:
Adder();
int add(int x,int y){
return x+y;
}
};
Simple enough, following the example i found from
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_12_section_3.html
.
But when i want to create an instance in my ViewController class see beblow,
it won't build.
It seems the way that i'm including Adder.cpp is wrong.
So i tried to separate the Adder.cpp into Adder.h and Adder.cpp.
It builds, but when i use Adder *adder to declare an instance, it won't
build again.
I've been through this problem for two days and i hope someone could help me
on this.
Thanks a lot,
Tang
*/Users/tangke/Documents/iPhoneApp/gb2/Classes/Adder.cpp:10: error: syntax
error before 'Adder'*
*/Users/tangke/Documents/iPhoneApp/gb2/Classes/Adder.cpp:10: error: syntax
error before '{' token*
*/Users/tangke/Documents/iPhoneApp/gb2/Classes/Adder.cpp:16: error: syntax
error before '}' token*
#import <UIKit/UIKit.h>
#include "Adder.cpp"
@interface gb2ViewController : UIViewController {
IBOutlet UILabel *label;
// Adder *adder;
}
@property(nonatomic, retain)UILabel *label;
-(IBAction)add:(id)sender;
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden