I have a C++ library that doesn't use namespaces. I want to port it to Objective-C. The problem is the name collisions between the two. I want it to have the same name in Objective-C that is the name of the C++ object. Bu开发者_运维百科t, I just can't figure out the best way to do this without it just becoming a mess. I am hoping for a solution to this.
Prefix all your Objective-C classes in the same way as you would writing a framework on the Mac and Apple does with its frameworks.
You can use #define
and #undef
to temporarily rename the classes/functions etc in your code - just make sure they are undef'ed when calling the C++ code.
e.g. in the header(s) for your wrapper have #define Bar_Function Foo_Function
, then surround the bits of code that call the library's Bar_Function with #undef Bar_Function
and #define Bar_Function Foo_Function
Now the only problem comes when you need to export your own Bar_Function...
Don't do this though - its silly, just work around it. :)
精彩评论