title: How to obtain the address of object in objective-C
body: <p>I have to call an objective C method from a cpp Function.</p>
  
  <p>I have a class C, whose object address is required in this function. I did come across <a href="https://stackoverflow.com/questions/304885/unable-to-call-an-objective-c-method-from-a-c-function">another link</a> which guided me on how to have a reference to the class C, and use it for invocation from the cpp function.</p>
  
  <p>In my case, there is one small difference in that the Class C is already instantiated, and I would not want to allocate an object again. So how can I get its object address?</p>
  
  <p>The code looks like this:</p>
  
  <h1>C.h</h1>
  
  <pre><code>import Cocoa/Cocoa.h
  
  id refToC
  
  @interface C: NSObject
  {
  
  ;
  
  somemethod;
  
  ;
  }
  
  @end
  </code></pre>
  
  <h1>C.m</h1>
  
  <pre><code>@implementation C
  
  - (void) somemethod
  {
  ;
  ;
  }
  
  @end
  </code></pre>
  
  <h1>B.mm</h1>
  
  <pre><code>import C.h
  
  void func()
  {
  
  //I need the address of object here, so as to invoke:
  [refToC somemethod];
  }
  </code></pre>
  
  <p>Thanks in Advance</p>
  
  <p>~ps7</p>