Icestorm
Icestorm

Reputation: 197

Objective C implementation with C++ Api

Lets I have C++ header such as:

    class Color 
{
public:
    Boolean OnInitDialog();
 };

Could I do the implementation in ObjectiveC with something like:

-(BOOL) OnInitDialog
{
...
return TRUE;
}

Upvotes: 0

Views: 349

Answers (3)

Cesar A. Rivas
Cesar A. Rivas

Reputation: 1355

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

Upvotes: 0

filipe
filipe

Reputation: 3380

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.

Upvotes: 2

Ben Scheirman
Ben Scheirman

Reputation: 40951

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?

Upvotes: 1

Related Questions