• 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
Re: calling an Objective C method from C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling an Objective C method from C++


  • Subject: Re: calling an Objective C method from C++
  • From: Andres Santiago Perez-Bergquist <email@hidden>
  • Date: Thu, 27 Feb 2003 13:09:25 -0500

On Thursday, February 27, 2003, at 11:20 AM, Paul Cezanne wrote:

I'm trying to call an Objective-C method from a C++ object. Converting the C++ object to Obj-C is not an option, this is cross platform code.

Here is what I've done so far:

I define a C++ wrapper class with a pointer to the Obj-C object:

class CFooWrapper
{
public:
void myTest(int j, , char *str);
void setMyController(id c);
private:

id my_Controller;
};

Then implement this class, calling objc_send to send the onJunk message to the receiver:

void CFooWrapper:: myTest(int j, char *str)
{
printf("j=%d, str=%s\n", j, str);
SEL aSel = @selector(onJunk:label:);
objc_msgSend(my_Controller, aSel, j, titleStr);
}

You should just be able to do "[myController onJunk:j label:titleStr];" (at least if you follow the advice below).

At first I thought that I wasn't compiling with the Objective-C compiler, so I changed it to be a .m file. That didn't help.
It seems that when compling this file, the compiler doesn't know what id is. How can I make it know that? Thanks.

Make it a .mm file, for Objective-C++.

-- Andres
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: calling an Objective C method from C++
      • From: Paul Cezanne <email@hidden>
References: 
 >calling an Objective C method from C++ (From: Paul Cezanne <email@hidden>)

  • Prev by Date: Re: NSBezierPath illustrations
  • Next by Date: ANN:JMRatingsView
  • Previous by thread: NSOutlineView and expanded items
  • Next by thread: Re: calling an Objective C method from C++
  • Index(es):
    • Date
    • Thread