开发者

Using C++ objects/classes with Objective C protocol

开发者 https://www.devze.com 2023-03-01 00:58 出处:网络
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

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开发者_StackOverflow社区;
    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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消