Objective C implementation with C++ Api
Lets I have C++ header such as:
class Color
{
public:
Boolean O开发者_高级运维nInitDialog();
};
Could I do the implementation in ObjectiveC with something like:
-(BOOL) OnInitDialog
{
...
return TRUE;
}
you could create an Objective-C class and then write a c++ wrapper for it. Something along the lines of
color.h
@interface Color : NSObject
{
...
}
- (BOOL) onInitDialog;
@end
color.m
#import "color.h"
@implementation Color
- (BOOL) onInitDialog
{
return YES;
}
@end
colorwrapper.h
#ifdef __OBJC__
@class Color;
#else
struct Color;
#endif
class ColorWrapper
{
Color *color;
public:
Boolean OnInitDialog();
};
colorwrapper.mm
#include "ColorWrapper.h"
Boolean ColorWrapper::OnInitDialog()
{
return [color onInitDialog];
}
Of course this is not complete code and probably is not completely right... but you get the general idea.
I don't think that's possible.
You can, however utilize C++ code in your implementation just by naming the file .mm
instead of .m
.
Curious, why would you want to do such a thing?
if your header is C++, your implementation should be C++. If your header is Objective C, your implementation should be Objective C.
you could use C++ and Obj-C together. http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html
精彩评论