2011-11-22 40 views
0

我有一個C語言風格類聲明:如何使用一個NSInteger在一個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) 
+0

'int'?也許我誤解了。 :p – Kjuly

+3

C不知道類。這是C++。你有沒有導入基金會的標題? – vikingosegundo

+0

我不能導入他們沒有得到大量的錯誤,如「NSObjCRuntime.h:在'@'令牌之前期望的非限定id我仍然不明白爲什麼我不能在.h文件中使用它 –

回答

2

您不包括標題從你自己的頭文件(可能是Foundation.h)定義NSInteger。推測你這樣做在你的.mm文件中。只需將#import#include指令移動到您的標題中即可。

+0

不,我不會導入任何東西,除了我的.h文件,如果我在.h中添加了foundation.h,我會在文件中得到很多錯誤的框架 –

0

你有:

#import <UIKit/UIKit.h>(IOS) 或

#import <Cocoa/Cocoa.h>(Mac OS)中

..imported在您的.h文件的頂部?

你確定你有所有的框架鏈接到你的項目?

foundation.framework 
appKit.framework 
UIKit.framework 
+0

NSInteger DO在.mm文件中工作,所以是的,我把所有這些東西鏈接起來。 –