不兼容的整数到指针转换从'int'分配给'int *' [英] Incompatible integer to pointer conversion assigning to 'int *' from 'int'

查看:512
本文介绍了不兼容的整数到指针转换从'int'分配给'int *'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还想要另一个令人讨厌的警告。基本上,我有一个这样声明的int: @property(nonatomic,assign)int * myInt; 并设置如下: myInt = 0; 。它也在实现文件中合成。我在设置int的值的行上收到警告,并且说指针转换的不兼容intiger从'int'分配给'int *'。我该怎么办解决这个问题?

I have yet another pesky warning I would like gone. Basically, I have an int declared like this: @property (nonatomic, assign) int *myInt; and set like this: myInt = 0;. It is also synthesized in the implementation file. I am getting a warning on the line where I set the int's value and it says Incompatible intiger to pointer conversion assigning to 'int *' from 'int'. What should I do to fix this?

推荐答案

错误信息中有一个很大的提示!

There's a big hint in the error message!

在C和Objective C中, int 是原始数据类型。你写了 int * ,这意味着指向一个int的指针,而你看起来只是想要一个int。

In C and Objective C, an int is a primitive data type. You've written int *, which means "a pointer to an int", whereas it looks like you just wanted an int.

所以将您的属性更改为:

So change your property to this:

@property (nonatomic, assign) int myInt;

欲了解更多信息,谷歌C指针,你会发现这样的信息: http://pw1.netcom.com/~tjensen/ptr/pointers.htm

For more info, google "C pointers" and you'll find information like this: http://pw1.netcom.com/~tjensen/ptr/pointers.htm

这篇关于不兼容的整数到指针转换从'int'分配给'int *'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆