Mithin
Mithin

Reputation: 971

Using C++ objects/classes with Objective C protocol

Hi trying the compile Objective C++/Protocol code but the compilation fails with error “Expected declaration specifier before protocol” and similar error for all the objective c line of code in the following header.

#import <UIKit/UIKit.h>

#include <Category>

@protocol StoreDelegate <NSObject>
@optional
...//Protocol methods
...
...

@end

@interface Store : NSObject {
    id<StoreDelegate> delegate;
    BOOL downloadFailed;
    Category *currentCategory;
}

@property(nonatomic, assign) id<StoreDelegate> delegate;

+ (Store *)sharedStore;
...//Class methods
...
...
@end

Note that “Category” is a C++ class. If I remove the protocol related code from the class then the code compiles fine. Is there a way to restructure the above code and get it compile?

Upvotes: 2

Views: 1355

Answers (1)

JeremyP
JeremyP

Reputation: 86651

You are probably including that header in a pure C++ source file. Make sure that any files that include that header are compiled as Objective-C++ either by changing the extension to .mm or by changing the file type to sourcecode.cpp.objcpp in the genral tab of the info window.

Upvotes: 2

Related Questions