Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在c风格的类声明中使用NSInteger_C++_Cocoa_Objective C++ - Fatal编程技术网

C++ 如何在c风格的类声明中使用NSInteger

C++ 如何在c风格的类声明中使用NSInteger,c++,cocoa,objective-c++,C++,Cocoa,Objective C++,我有一个c风格的类声明: #pragma once class CSound { private: NSInteger bufferID; public: CSound(const char* fileName); ~CSound(); static void init(); void play(); }; 编译器说,NSInteger没有命名类型 如果我将“NSInteger bufferID;”放在.mm文件中(而不是.h文件中),它会工作。我做错

我有一个c风格的类声明:

#pragma once

class CSound
{
private:
   NSInteger bufferID;
public: 
    CSound(const char* fileName);
    ~CSound();
    static void init();
    void play();
};
编译器说,NSInteger没有命名类型

如果我将“NSInteger bufferID;”放在.mm文件中(而不是.h文件中),它会工作。我做错了什么

编辑

由于我仍然没有解决方案,我做了一个快速肮脏丑陋的修复:

在.h文件中,在类定义中

void* pBufferID;
在.mm文件中

// constructor
pBufferID = new NSUInteger;

// destructor
delete (NSUInteger*)pBufferID;

// everywhere I use it
*((NSUInteger*)pBufferID)

您不包括从您自己的头文件(可能是基础.h)定义<代码> NSInteger <代码>的页眉。大概您是在
.mm
文件中这样做的。只需将
#import
#include
指令移动到标题中即可。

您是否有:

#导入
(iOS) 或

导入(Mac OS)

…是否在.h文件的顶部导入

你确定所有的框架都链接到你的项目上了吗

foundation.framework
appKit.framework
UIKit.framework

int
?也许我误解了电脑不知道上课。这是C++。是否导入了基础首部?我不能导入它们而不会产生大量错误。NSObjCRuntime.h:在“@”标记之前应为非限定id。我仍然不明白为什么我不能在.h文件中使用它。我知道C不知道类。。。但是c++风格这个词看起来不太好:)不,除了.h文件,我什么都不导入。如果在My.h中添加Fuff.h,我会在文件的框架中得到大量错误。NSnWork确实在.mm文件中工作。所以是的,我把这些东西都联系起来了。