how to build c++ file and create its instance in another objective-c class

  • 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/Articl
    es/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
  • Le 6 juin 08 à 16:53, Tang Ke a écrit :

    > 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/Articl
    es/chapter_12_section_3.htm


    The first thing to do it to learn how to search the mailine list
    archive. For example try to search for iPhone and NDA:

    http://www.cocoabuilder.com/search/archive/cocoa?words=iphone+nda

    Then try to compile your file as an obj-c++ file and not as a C++
    file. To do this, rename it using the .mm extension (instead of .m
    or .cpp).
  • Hi Jean,

    Merci!

    I tried to rename it to Adder.mm, also tried to rename my viewcontroller to
    viewcontroller.mm, it didn't work. I searched google, ADC, and cocoadev.com,
    and really couldn't find an answer.

    Cheers,

    Tang

    2008/6/6 Jean-Daniel Dupas <devlists...>:

    >
    > Le 6 juin 08 à 16:53, Tang Ke a écrit :
    >
    > 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/Articl
    es/chapter_12_section_3.htm

    >>
    >
    >
    > The first thing to do it to learn how to search the mailine list archive.
    > For example try to search for iPhone and NDA:
    >
    > http://www.cocoabuilder.com/search/archive/cocoa?words=iphone+nda
    >
    > Then try to compile your file as an obj-c++ file and not as a C++ file. To
    > do this, rename it using the .mm extension (instead of .m or .cpp).
    >
    >
    >
    >
  • That's odd, when I search iPhone + NDA on this list a got a lots of
    answer like thoses ones:

    “As ever, the iPhone SDK is under the NDA you agreed to. You cannot
    discuss it here.”

    “This is the point where we slam up hard against the non-disclosure
    agreement to which we all had to agree to even know that video
    existed, much less access it. As has been beaten to death on this list
    many times before (is there even anything left of that carcass any
    more?), we can't discuss that here.”

    “iPhone SDK is under NDA (non-disclosure agreement) and cannot be
    discussed via a channel such as this list.”

    And a lot of others like this.

    Try to create a simple Xcode / Cocoa (not Cocoa touch) project at
    first. It's very similar and you may get some help from people here.

    Le 6 juin 08 à 17:04, Tang Ke a écrit :

    > Hi Jean,
    >
    > Merci!
    >
    > I tried to rename it to Adder.mm, also tried to rename my
    > viewcontroller to viewcontroller.mm, it didn't work. I searched
    > google, ADC, and cocoadev.com, and really couldn't find an answer.
    >
    > Cheers,
    >
    > Tang
    >
    > 2008/6/6 Jean-Daniel Dupas <devlists...>:
    >
    > Le 6 juin 08 à 16:53, Tang Ke a écrit :
    >
    >
    > 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/Articl
    es/chapter_12_section_3.htm

    >
    >
    > The first thing to do it to learn how to search the mailine list
    > archive. For example try to search for iPhone and NDA:
    >
    > http://www.cocoabuilder.com/search/archive/cocoa?words=iphone+nda
    >
    > Then try to compile your file as an obj-c++ file and not as a C++
    > file. To do this, rename it using the .mm extension (instead of .m
    > or .cpp).
    >
    >
    >
    >
    >
  • Can you please provide a sample with one cocoa file (.m & .h) and c++ file
    (.mm & .h) plase?

    Thanks

    Kartik


    -----Original Message-----
    From: cocoa-dev-bounces+kganesan=<databasepublish.com...>
    [mailto:cocoa-dev-bounces+kganesan=<databasepublish.com...>] On
    Behalf Of Jean-Daniel Dupas
    Sent: Friday, June 06, 2008 11:00 AM
    To: Tang Ke
    Cc: <Cocoa-dev...>
    Subject: Re: how to build c++ file and create its instance in
    anotherobjective-c class

    Le 6 juin 08 à 16:53, Tang Ke a écrit :

    > 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/Articl
    e

    s/chapter_12_section_3.htm

    The first thing to do it to learn how to search the mailine list
    archive. For example try to search for iPhone and NDA:

    http://www.cocoabuilder.com/search/archive/cocoa?words=iphone+nda

    Then try to compile your file as an obj-c++ file and not as a C++
    file. To do this, rename it using the .mm extension (instead of .m
    or .cpp).
previous month june 2008 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
Go to today