• 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: Objective-C++ and NSInvocation (or IMP)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C++ and NSInvocation (or IMP)


  • Subject: Re: Objective-C++ and NSInvocation (or IMP)
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 30 May 2007 09:58:51 +0100

On 30 May 2007, at 04:53, E. Wing wrote:

- (std::string) appendString:(std::string)begining
withString:(std::string)ending;

The problem is probably that ObjC type introspection, on which NSInvocation depends, does not support C++ objects (though it does support structs, so it may be treating the string as a struct argument, but that could break things depending on the std::string implementation).


If you were to pass a *pointer* to an std::string instead, it might then work. I doubt a reference would work since I don't think there's even an ObjC type code for a C++ reference.

If you're interested, you might try calling -getArgumentTypeAtIndex: on your NSMethodSignature to see what type information is actually present for the arguments you're having trouble with.

As far as the IMP approach goes, it *will* work, but you'll have to cast your IMP to a pointer with the correct type. So it should look like this:

std::string (*imp)(id, SEL, std::string, std::string) = [myObject methodForSelector:@selector(appendString:withString:)];
imp(myObject, @selector(appendString:withString:), "foo", "bar");


Obviously NSInvocation is a more general way to call arbitrary ObjC methods.

Kind regards,

Alastair.

--
http://alastairs-place.net
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Objective-C++ and NSInvocation (or IMP)
      • From: "E. Wing" <email@hidden>
References: 
 >Objective-C++ and NSInvocation (or IMP) (From: "E. Wing" <email@hidden>)

  • Prev by Date: Re: Window freezes app
  • Next by Date: NSBrowser is asking for wrong column
  • Previous by thread: Re: Objective-C++ and NSInvocation (or IMP)
  • Next by thread: Re: Objective-C++ and NSInvocation (or IMP)
  • Index(es):
    • Date
    • Thread