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. But, 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.
+1
A:
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.
JeremyP
2010-10-13 09:10:59
both the base class and the class i'm trying to create is both prefixed.
zekecoma
2010-10-14 03:21:57
Well use a different prefix for the OC classes.
JeremyP
2010-10-14 08:24:09
A:
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. :)
jheriko
2010-10-14 20:57:18