• 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
Calling an Obj-C method from a C++ class, how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calling an Obj-C method from a C++ class, how?


  • Subject: Calling an Obj-C method from a C++ class, how?
  • From: Rolf Nilsson <email@hidden>
  • Date: Thu, 7 Oct 2004 15:17:48 +0200



Hi,

My app has a Cocoa GUI but most of the code is C++.

My problem is how to call an Obj-C method from a C++ class.


This is what I do:

When I create my C++ object in my Cocoa method, I supply a pointer to the Cocoa class:


@implementation MyController

- (void)someCocoaMethod
{
SomeCPPClass *p = new SomeCPPClass(self);
}


- (void) aCocoaMethodWithOneArgument:(int)theArgument;

- (void) aCocoaMethodWithTwoArguments:(int *)pAnIntPointer
anIntValue:(int) anIntValue;

@end



in my C++ class I want to be able to call either of the two methods aCocoaMethodWithOneArgument or aCocoaMethodWithTwoArguments


class SomeCPPClass
{
public:

SomeCPPClass(MyController *pMyControllerCocoaObj) { m_pMyControllerCocoaObj = pMyControllerCocoaObj; }

void foo();

protected:
MyController *m_pMyControllerCocoaObj;

}

// here I want to call (send a message to ) the Obj-C method
void SomeCPPClass::foo()
{
int * pAnIntPointer;
int anIntValue;

............
other code here
............


// this works for a method with one argument but there may be a better way?
[ (id)m_pMyControllerCocoaObj performSelector:@selector(aCocoaMethodWithOneArgument:) withObject: (id) pAnIntPointer];

}


But, I can't find out how to call the method with two arguments?


Thanks for any help,
Rolf


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Calling an Obj-C method from a C++ class, how?
      • From: Karin Kosina <email@hidden>
  • Prev by Date: Re: Boggled By Bindings
  • Next by Date: How to get default date format?
  • Previous by thread: Multi-window documents
  • Next by thread: Re: Calling an Obj-C method from a C++ class, how?
  • Index(es):
    • Date
    • Thread