我正在尝试使用 boost 库类进行一些套接字通信。我需要将此变量声明为类实例,因此我声明如下,
@interface Custom_View : UIView{
boost::asio::io_service io_service_2;
tcp::resolver r_2(io_service_2);
client c_2(io_service_2);
boost::thread* dvr_thread_2;
}
越来越像
Custom_View.h:46:23: Unknown type name 'io_service_2'; did you mean 'boost::asio::io_service'?
Custom_View.h:47:16: Unknown type name 'io_service_2'; did you mean 'boost::asio::io_service'?
Custom_View.h:46:19: Field 'r_2' declared as a function
Custom_View.h:47:12: Field 'c_2' declared as a function
我该如何解决这个错误。
最佳答案
如果您尝试声明一个 Objective-C 类或静态变量,则必须在 @interface 声明中的花括号之外进行。例如(如果您没有声明任何实例变量,可以省略“{}”):
@interface SubclassName : SuperclassName
Type variableName;
也就是说,我不熟悉 boost 库,而且您代码中声明的变量似乎不是有效的 Objective-C。快速 Google 搜索显示了这个 GitHub 项目,它可能会帮助您找到正确的方向:https://github.com/mz2/boostoniphone
关于IOS 将 boost 类声明为类变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38748949/