Objy-C包装器不是Objto-C代码实现的。,c++,ios,iphone,objective-c,C++,Ios,Iphone,Objective C" /> Objy-C包装器不是Objto-C代码实现的。,c++,ios,iphone,objective-c,C++,Ios,Iphone,Objective C" />

如何为C++; 我在编写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(); } < C++ > Objy-C包装器不是Objto-C代码实现的。

如何为C++; 我在编写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(); } < C++ > Objy-C包装器不是Objto-C代码实现的。,c++,ios,iphone,objective-c,C++,Ios,Iphone,Objective C,要实现它,请使用纯C函数 在纯C函数下,实现objective-C代码。在C++代码中,使用C函数调用Objtovi-C代码。 ObjuleC不理解C++。< /P> < >使用ObjtoVC++使用C++代码。 在ObjuleC++中,可以使用C++代码。将文件另存为.mm而不是.m 编辑: 代码中的错误是因为编译器无法找到结构的定义。编译器需要知道结构的大小。如果没有其定义,则无法创建对象。即使在堆栈上创建对象也是如此。至少应该包括关于问题中的错误的细节。您的代码>打印< /COD>结构声

要实现它,请使用纯C函数

在纯C函数下,实现objective-C代码。在C++代码中,使用C函数调用Objtovi-C代码。

ObjuleC不理解C++。< /P> < >使用ObjtoVC++使用C++代码。 在ObjuleC++中,可以使用C++代码。将文件另存为.mm而不是.m

编辑:


代码中的错误是因为编译器无法找到结构的定义。编译器需要知道结构的大小。如果没有其定义,则无法创建对象。即使在堆栈上创建对象也是如此。

至少应该包括关于问题中的错误的细节。您的代码>打印< /COD>结构声明,谢谢您的评论,但是在代码中,我已经使用了ObjnC++。请参考我的代码cppWrapper.mm