title: Calling an objective c method using a function pointer from a c++ method
body: <p>I have a c++ class that needs to call an objective c method using a pointer to that method. This method returns void and takes an argument of type 'status' where status is a simple integral enum. </p>
  
  <pre><code> enum status
   {
         status_valid = 0,
         status_invalid,
         status_unknown
   };
  </code></pre>
  
  <p>I have the pointer to the obj-c method set up like this. The pointer to the method is also being passed to the c++ class and</p>
  
  <pre><code>typedef void (*FuncPtr) (status);
  FuncPtr myObjCSelectorPointer = (void (*)(status))[self methodForSelector:@selector(statusChanged: )];
  cppClassInstance-&gt;setFuncPointer(myObjCSelectorPointer)
  </code></pre>
  
  <p>myObjCSelectorPointer is being held on to by the cppClass like this: </p>
  
  <pre><code>void cppClass::setFuncPointer(FunctPtr *ptr)
  {
       this-&gt;funcPtr = ptr;
  }
  </code></pre>
  
  <p>Now somewhere else, when I try to call the method pointed to by this pointer, like this: </p>
  
  <pre><code>status s;
  funcPtr(s);
  </code></pre>
  
  <p>The method gets called correctly, but the value passed into the method is lost. The obj-c method receives a completely random value. When I try to call a method in the cpp class using the same way, it passes and receives the correct value. </p>
  
  <p>What am I doing wrong? Can you not call an objective c method like this? </p>