coffee_machine
coffee_machine

Reputation: 1223

How to use an NSInteger in a c-style class declaration

I have a c-style class declaration:

#pragma once

class CSound
{
private:
   NSInteger bufferID;
public: 
    CSound(const char* fileName);
    ~CSound();
    static void init();
    void play();
};

The compiler says NSInteger does not name a type.

If I put the "NSInteger bufferID;" in the .mm file (not in the .h) it works. What am I doing wrong?

EDIT

As I still have no solution, I did a quick dirty-ugly-fix:

in .h file, in the class definition

void* pBufferID;

and in the .mm file

// constructor
pBufferID = new NSUInteger;

// destructor
delete (NSUInteger*)pBufferID;

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

Upvotes: 0

Views: 917

Answers (2)

d.ennis
d.ennis

Reputation: 3455

Do you have the:

#import <UIKit/UIKit.h> (iOS) or

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

..imported at the top of your .h file?

And are you sure you have all the frameworks linked to your project?

foundation.framework
appKit.framework
UIKit.framework

Upvotes: 0

Carl Norum
Carl Norum

Reputation: 225032

You're not including the header that defines NSInteger from your own header file (probably Foundation.h). Presumably you are doing so in your .mm file. Just move that #import or #include directive into your header.

Upvotes: 2

Related Questions