开发者

Private Methods in ObjC++

I need to rename a ObjC Class Implementation File into *.mm, because I'm using a C++ Framework (Box2D). After renaming the file and setting the Filetype to "sourcecode.cpp.objcpp" my following declaration of private methods produces some errors like:

error: expected identifier before 'private'

The declaration of methods:

@interface Gamepl开发者_如何学JAVAayLayer(private)
 - (void)spawnTick:(ccTime)delta;
 - (void)pushSpawnTick;
@end

How can I use declarations of private methods in ObjC++?


It is probably because private is a keyword in C++. You can either change it to something else like hidden or leave the category name empty (this is called a 'class continuation', you can read more about it by searching in this article.)


this is the way I declare my private methods in Obj-C basically is just creating a category with no name in the .m hope this helps

//this is A.h

@interface A

- (void) publicMethod1;

@end



//this is A.m

@interface A ()

- (void) privateMethod1;

@end

@implementation A

- (void) publicMethod1
{
    //foo
}

- (void) privateMethod1
{
    //foo
}

@end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜