ios - Using an Objective-C SDK in a C++ class -


i have c++ project needs make use of objective-c sdk. idea create c++ class in .mm file contains calls sdk in objective-c syntax. declare instance of class in existing c++ project (which has .cpp files).

will work? gather, ".mm" file objective-c++ file, can make calls objective-c functions? can cpp file instanciate class defined in .mm file?

define class in header , include in both objective-c++ file defines members of class , c++ file uses class.

if need store objective-c types, wrap them in opaque structure.

illustration:

"c.h":

class c {     public:         c();         void foo();     private:         struct data;         data* m_data; }; 

implementation in objective-c++:

#include "c.h"  struct c::data {     sometypeinyoursdk* thing; };  c::c() {     m_data = new data;     m_data->thing = [sometypeinyoursdk createsomehow]; }  void c::foo() {     [m_data->thing dosomething]; } 

use in c++:

#include "c.h"  void bar() {     c c;     c.foo(); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -