1

最初我在 LoginViewController.m 中有包含以下警告的文件,我忽略了它。并且代码工作正常。

warning: sending 'LoginViewController *' to parameter of incompatible type 'id<NSStreamDelegate>'

但现在我将文件扩展名更改为 .mm (LoginViewController.mm)。由于此错误,现在我无法再构建项目。

Cannot initialize a parameter of type 'id<NSStreamDelegate>' with an lvalue of type 'LoginViewController *'

怎么了?

4

2 回答 2

6
warning: sending 'LoginViewController *' to parameter of incompatible type 'id<NSStreamDelegate>'

此警告是由于NSStreamDelegate您在定义类时不符合协议LoginViewController。理想情况下,您的类应该符合该协议,以便当您将其设置为委托时,它可以理解您正在实现它期望的任何委托方法。

例如:-

@interface LoginViewController : UIViewController<NSStreamDelegate> {}

一旦你解决了这个问题,当你更改为 .mm 类时,你不应该得到另一个错误。

于 2013-03-08T23:36:04.743 回答
2

C++ 的类型规则比 C 更严格。 LoginViewController 没有声明符合该协议,因此指针类型不兼容,这是 C++ 中的硬错误。声明一致性应该解决它。(您可能仍然会遇到比以前更多的类型错误,因为 C 中的静默转换需要 C++ 中的强制转换。)

于 2013-03-08T23:05:57.903 回答