title: Access Objective-C variable from C++ function
body: <p>I'm working on a project that just needs to be rewritten but that is not an option at this point.</p>
  
  <p>I have a C++ function that is called and does all kinds of stuff.  I need it to read a variable from the App Delegate class.</p>
  
  <p>For example I have:</p>
  
  <pre><code>@interface MyAppDelegate : NSObject &lt;UIApplicationDelegate&gt; 
  {
      UIWindow *window;
      MyViewController *viewController;
  
   int mToleranceLevel;
  }
  </code></pre>
  
  <p>I then have a function that needs to access the mToleranceLevel:</p>
  
  <pre><code>bool FindExtrinsics(...)
  {
   float maxError = mainDelegate.mMaxError;
          ...
  }
  </code></pre>
  
  <p>The problem is that this was declared like so:</p>
  
  <pre><code>@interface MyClass : UIViewController 
  {
    ...
  }
  
  @properties ...
  
  bool FindExtrinsics(...);
  
  @end
  </code></pre>
  
  <p>So how would I get a value from the AppDelegate class.  I do know how to get the current delegate:</p>
  
  <pre><code>mainDelegate = (RedStripeARAppDelegate *)[[UIApplication sharedApplication] delegate];
  </code></pre>
  
  <p>But how do I use this info to get the value in my C++ function.  Is there a way to make a static variable so I can call MyAppDelegate.mToleranceValue;??</p>