RE:Using C++ classes with Objective C code
RE:Using C++ classes with Objective C code
- Subject: RE:Using C++ classes with Objective C code
- From: Brant Sears <email@hidden>
- Date: Fri, 10 Oct 2003 11:07:56 -0700
>
At first it would not compile, but after cleaning the target, it
>
compiled, but now it will not link.
This is a name mangling issue. C++ "mangles" the symbol so that it can
figure out which version of a particular method you meant. This is because
of the function overloading feature of C++ (which Obj-C doesn't have.)
So, when you are in a .mm or .cpp file and you include your .h file with
function prototypes, it assumes you mean the mangled symbols. When you
include the same header from your .m files and .c files, it assumes you mean
a non-mangled symbol.
The solution is to declare your interface to be non-mangled using extern
"C".
So, your file "interface.h" would look like this:
#ifdef __cplusplus
extern "C"
{
#endif
void foo(char* , int, UInt32 *);
void bar(char*, int *);
#ifdef __cplusplus
}
#endif
Remember that your .m and .c files won't even understand (and don't need)
extern "C", so that's why you have to use the preprocessor. __cplusplus will
be defined when you are including from a .cpp or .mm file.
Brant Sears
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.