• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
how to build c++ file and create its instance in another objective-c class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: how to build c++ file and create its instance in another objective-c class
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Re: Regular Expressions?
  • Next by Date: Re: how to build c++ file and create its instance in another objective-c class
  • Previous by thread: Re: Installing Spin Control alone
  • Next by thread: Re: how to build c++ file and create its instance in another objective-c class
  • Index(es):
    • Date
    • Thread