不兼容的整数到指针转换从'int'分配给'int *'

编程入门 行业动态 更新时间:2024-10-21 03:26:45
本文介绍了不兼容的整数到指针转换从'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指针,你会发现这样的信息: pw1com/~tjensen/ptr/pointers.htm

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

更多推荐

不兼容的整数到指针转换从'int'分配给'int *'

本文发布于:2023-07-29 08:51:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   指针   不兼容   int

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!