[英]objective-c why a .mm file is considered a int* type?
I am trying to create a weak reference of a .mm class... the problem is the file even though code-wise its a NSObject class it considers it as a int* type. 我正在尝试创建.mm类的弱引用...问题是文件,即使按代码方式将其视为NSObject类,也将其视为int *类型。 If I change the file back to .m though it accepts it as a Obj-c class but the code stops working because of cocos2d requirement of files being .mm 如果我将文件改回.m,尽管它将它作为Obj-c类接受,但由于文件的cocos2d要求是.mm,所以代码停止工作
//Game Logic is actually NSObject meaning obj-c class.
@interface GameLogic : NSObject
//However here I get the error like the file is type int*
@property (weak,nonatomic)GameLogic * __weak gameLogicWeak;
Those are the 2 msgs I get. 这些是我得到的2个味精。
Property with 'weak' attribute must be of object type
'__weak' only applies to Objective-C object or block pointer types; type here is 'int *'
Anyone has any idea what can I do to overcome this problem? 任何人都知道如何解决该问题? I know there exists many solutions, one of them would be just not create that weak link, use delegate, or well many other possible solutions. 我知道存在许多解决方案,其中之一就是不创建薄弱的链接,使用委托或其他许多可能的解决方案。
But this solution was a cleaner one that I came up with which makes ARC come in handy with the memory clean up. 但是我想出了一种更清洁的解决方案,它使ARC可以很方便地进行内存清理。
Any suggestions? 有什么建议么? Workarounds? 解决方法? Solutions? 解决方案? anyone has come with this problem? 有人有这个问题吗?
==== ====
I get the following message when @class GameLogic is added in .h and #import in the .m respectively. 当分别在.h和#import中将@class GameLogic添加到.m中时,出现以下消息。 This message is generated in a location where I am using the weak reference. 此消息是在我使用弱引用的位置生成的。
Receiver type 'GameLogic' for instance message is a forward declaration
Did you do 你做了
#import "GameLogic.h"
in the header where you added the property? 在您添加属性的标题中? You can also add 您也可以添加
@class GameLogic;
but not 但不是
class GameLogic;
because that would make it a forward reference to a C++ class. 因为这将使其成为对C ++类的前向引用。 Also double-check that you don't actually have a C++ class of the same name. 还要仔细检查您实际上没有同名的C ++类。
And is that header file's implementation also .mm? 头文件的实现也是.mm吗? Because it has to be if GameLogic allows direct access (property or return value) to a C++ class. 因为GameLogic必须允许直接访问(属性或返回值)C ++类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.