开发者

expected '=', ',', ';', 'asm' or '__attribute__' before 'sizeof'

开发者 https://www.devze.com 2023-03-06 11:38 出处:网络
@implementation classname static const unsigned int OFFSET_STX =0; static const unsigned int OFFSET_ETX =1;
@implementation classname

static const unsigned int OFFSET_STX =0;
static const unsigned int OFFSET_ETX =1;
static const unsigned int OFFSET_KTX =2;
static const unsigned int OFFSET_MTX =4;
static const unsigned int OFFSET_LTX =5;

static const char STX =0x05;
static const char ETX =0x09;

@end

Error:

expected '=', ',', ';', 'asm' or '__attribute__' before 'sizeof'

How do i declare these static variables inside the class.

Do i 开发者_Python百科need to declare

+(int)OFFSET_ETX
{
 return OFFSET_ETX=0;
}

and call through [classname OFFSET_ETX]; for every static variables. I am having more than 10 static variables to be assigned in my program.


You cannot put a static variable inside a class interface in Objective C. In Objective C, static has the same meaning as it does in C. Do this instead:

enum {
    OFFSET_STX = 0,
    OFFSET_ETX = 1,
    OFFSET_KTX = 2,
    OFFSET_MTX = 3,
    OFFSET_LTX = 4
};

@implementation classname
...
@end
0

精彩评论

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