views:

93

answers:

2

I'd like to use a C++ stack type in Objective-C, but I'm running into some issues. Here's a sample of what I would like to do:

#import <stack>
#import <UIKit/UIKit.h>

@interface A : NSObject {
    stack<SEL> selectorStack;
}

@end

Unfortunately, this doesn't compile. After messing around with the code for a while and trying different things, I can't seem to find a way to accomplish this. Can somebody tell me the best way to use a C++ stack within an Objective-C object or if it's even possible?

Thanks.

UPDATE:

Well, KennyTM's answer worked on my example file, but for some reason when I tried to rename the class it quit working. Here's the code I have right now:

#import <stack>
#import <UIKit/UIKit.h>

@interface MenuLayer : NSObject {
    std::stack<SEL> selectorStack;
}

@end

The compiler spits out the following errors:

stack: No such file or directory
expected specifier-qualifier-list before 'std'
+2  A: 

Have you tried

@interface A : NSObject {
    std::stack<SEL> selectorStack;
}
KennyTM
Hey, thanks for the quick reply. I feel kind of stupid for not specifying the fully qualified class name. When I changed this on my sample file, it fixed the problem. However, I tried changing the name of the class to something else and the compiler spit out a couple of new errors. I updated my post with more information. Thanks again.
helixed
+1  A: 

For the second problem make sure you haven't accidentally renamed the file ending .m instead of .mm. Otherwise the C++ headers aren't in the header search paths (and you can't use C++ of course).

Also, if the header is included in some plain Objective-C file (.m) you end up with the same problem. You could avoid this e.g. by using opaque pointers.

Georg Fritzsche