Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > I want to use a c++ object in a cocoa app

I want to use a c++ object in a cocoa app
Thread Tools
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Mar 27, 2003, 08:21 AM
 
I just got the brown cocoa book (great book btw, highly recommended!).

I have a main prog that I wrote in c++ a while ago. Basically there are three files..

myObject.h
myObject.cpp
myApp.cpp

all myApp does is make an instance off the Object and call some of its functions.

int main (void)
{
MyObject obj;
obj.func1();
obj.func2();
return 0;
}

For practice I wanted to put a gui ontop of this program.

I figured I could make a window with buttons and have each button call one of the functions.

Since this has to be in obj-c i made an object with two functions and I was going to have them turn around and call my c++ functions.

How do I include myObject.h in an obj-c file? I tried #include and got errors.

sorry if this is easy, i'm new to obj-c.

Thanks!
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Mar 27, 2003, 12:04 PM
 
You'll have to name your Obj-C file ".mm" to invoke the Obj-C++ compiler (which enables the combination of C++ and Obj-C++). See the Objective-C++ compiler release notes.
     
poulh  (op)
Mac Enthusiast
Join Date: Jun 2000
Location: New York, NY
Status: Offline
Reply With Quote
Mar 27, 2003, 02:26 PM
 
Thanks! I'll try it when I get home (and off this damn XP box).
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:57 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2