0

I mixed some C++ codes with Objective-C in class with .mm extension.

I synthesized some variables in Objective-C, and I want to retrieve those variables in C++ methods. How to do that?

I tried [self aVariable], this->aVariable to retrieve the synthesized variables, but failed.

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
user403015
  • 7,209
  • 19
  • 66
  • 100

2 Answers2

1

You cannot use self in a C++ class. this->aVariable doesn't say anything. It doesn't say whether you are trying to call a method. In fact it doesn't do anything with aVariable.

I assume the method is attached to an objective-C object. If so call it as follows from the C++ class:

[aVariable <method>];
Goz
  • 61,365
  • 24
  • 124
  • 204
-1

I fixed my problem after reading this post:

Calling Objective-C method from C++ method?

Community
  • 1
  • 1
user403015
  • 7,209
  • 19
  • 66
  • 100
  • Why does `self` need to be typed as `void*`? Just do `void doSomething(id self)`. Of course, you could have understood all of this instantly by actually knowing any C, or by reading Apple's guide to Objective-C. – Jonathan Sterling Nov 18 '10 at 16:23
  • I tried your suggestion - void doSomething(id self), but it does not compile. "void *self" works, but I don't know why, since I am new in C++. – user403015 Nov 18 '10 at 16:57
  • @user403015: what error(s) do you get when compiling? If you give us sufficient information, we can help you. – outis Nov 19 '10 at 00:51