• 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
Objective-C++: passing Objective-C objects to C++ methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C++: passing Objective-C objects to C++ methods?


  • Subject: Objective-C++: passing Objective-C objects to C++ methods?
  • From: <email@hidden>
  • Date: Sat, 11 Nov 2006 23:21:29 -0500

I am new to Objective-C++, and I am having some problems. I'm using
a recent snapshot of GCC 4.2, for the record.

Passing a statically typed Objective-C object to a C++ function
with a parameter of type id works fine. However, I get compilation
errors when passing the same statically typed Objective-C object to
a method of a C++ class that has a parameter of type id.

I'm also getting errors when (in this case) I'm passing Objective-C
classes of type Test, but declared to be of type id, to C++ object
methods expecting an argument of type Test*.

I'm getting these errors:
  test.mm: In function 'int main(int, char**)':
  test.mm:51: error: no matching function for call to
'printer::print_Test(objc_object*&)'
  test.mm:33: note: candidates are: void printer::print_Test(Test*)
  test.mm:53: error: no matching function for call to
'printer::print_id(Test*&)'
  test.mm:37: note: candidates are: void
printer::print_id(objc_object*)

Here is the test.mm code in question:

----8<-----

#import <stdio.h>
#import <objc/Object.h>

@interface Test : Object {
  int i;
}

-(id) init:(int)n;
-(id) print;

@end


@implementation Test

-(id) init:(int)n {
  i = n;

  return self;
}

-(id) print {
  printf("%d\n", i);

  return self;
}

@end


class printer {
  public:
    void print_Test(Test* test) {
      [test print];
    }

    void print_id(id test) {
      [test print];
    }
};

int main(int argc, char** argv) {

  Test* test_Test = [[Test alloc] init:100];
  id test_id = [[Test alloc] init:200];

  printer p;

  p.print_Test(test_Test);
  p.print_Test(test_id);

  p.print_id(test_Test);
  p.print_id(test_id);

  return 0;
}

----8<-----

What I'd like to do is to be able to pass an Objective-C object
declared to be of type id, along with any statically typed
Objective-C object, to the C++ method. Is this something that can
be done in Objective-C++? How would one go about doing this?

Unfortunately, I don't have a Mac available to test this with. What
behavior does Apple's version of GCC exhibit for the above
Objective-C++ code? Does it compile?

Any help would be most appreciated.

- Frederik Smith







Concerned about your privacy? Instantly send FREE secure email, no account required
http://www.hushmail.com/send?l=480

Get the best prices on SSL certificates from Hushmail
https://www.hushssl.com?l=485

 _______________________________________________
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: Objective-C++: passing Objective-C objects to C++ methods?
      • From: Nick Zitzmann <email@hidden>
    • Re: Objective-C++: passing Objective-C objects to C++ methods?
      • From: "stephen joseph butler" <email@hidden>
    • Re: Objective-C++: passing Objective-C objects to C++ methods?
      • From: Shawn Erickson <email@hidden>
  • Prev by Date: Re: How to Optimize drawRect: for obscured views?
  • Next by Date: Re: Objective-C++: passing Objective-C objects to C++ methods?
  • Previous by thread: Re: How to Optimize drawRect: for obscured views?
  • Next by thread: Re: Objective-C++: passing Objective-C objects to C++ methods?
  • Index(es):
    • Date
    • Thread