This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

I've run into some problems with Objective-C++ while using the gcc-
4.2-20061107 snapshot.

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: In function 'int main(int, char**)': error: no matching function for call to 
'printer::print_Test(objc_object*&)' note: candidates are: void printer::print_Test(Test*) error: no matching function for call to 
'printer::print_id(Test*&)' note: candidates are: void 

Here is the code in question:


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

@interface Test : Object {
  int i;

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


@implementation Test

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

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


class printer {
    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;

  return 0;


While I can't test it myself at the moment, this code reportedly 
works fine with Apple's compiler [1][2]. Is this a bug/restriction 
with GCC's implementation of Objective-C++, or is the above code 



Concerned about your privacy? Instantly send FREE secure email, no account required

Get the best prices on SSL certificates from Hushmail

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]