我有一个关于为 c++ 编写目标 C 包装器的问题。当我尝试构建它时,这是我的代码中的错误。我不确定我做错了什么。非常感谢任何帮助或指导。以下是我编写的示例代码:
///Print.h///
int test1();
///Print.cpp///
int test1()
{
printf ("hello man\n");
}
///cppWrapper.h///
struct Print;
typedef struct Print Print;
@interface cppWrapper : NSObject
{
Print *print;
}
@property (nonatomic, assign) Print *print;
-(id)init;
-(int)runTest;
///cppWrapper.mm///
#import "cppWrapper.h"
@implementation cppWrapper
@synthesize print = _print;
- (id)init
{
self = [super init];
if (self)
{
_print = new Print(); //error occurred here.
}
return self;
}
-(int)runTest
{
self.print->test1();
}