swith 引起的: expected expression before 'XXX'的 error
2015-05-04 10:39
633 查看
今天在写switch的时候遇到个奇怪的问题:
case DEFAULT:
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
我直接在case 标签后面 声明 并定义一个 UIImage 对象,但是它提示 expected expression before UIImage的错误,搞了半天没明白哪里出了问题,最后上网找发现,像 case这类标签语句后面 你 不能立即放置一个声明语句, 它们 “can only precede a statement”(后面必须紧跟一个statement 不知道怎么翻译这个 statement )也就是说 在 UIImage前面随便加个 statement 就没问题,
case DEFAULT:
; (加了个分号)
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
或者你也可以将你的声明用大括号 括起来,
case DEFAULT:
{
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
}
总之我觉得这东西有点古怪,写下来提醒下自己
/article/10603893.html
case DEFAULT:
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
我直接在case 标签后面 声明 并定义一个 UIImage 对象,但是它提示 expected expression before UIImage的错误,搞了半天没明白哪里出了问题,最后上网找发现,像 case这类标签语句后面 你 不能立即放置一个声明语句, 它们 “can only precede a statement”(后面必须紧跟一个statement 不知道怎么翻译这个 statement )也就是说 在 UIImage前面随便加个 statement 就没问题,
case DEFAULT:
; (加了个分号)
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
或者你也可以将你的声明用大括号 括起来,
case DEFAULT:
{
UIImage *image1 = [UIImage imageNamed:@"fillcolor_10.png"];
image1 = [image1 convertToScaleWithColor:GRAYCOLOR];
}
总之我觉得这东西有点古怪,写下来提醒下自己
/article/10603893.html
相关文章推荐
- swith 引起的: expected expression before 'XXX'的 error
- ldd3 error: expected expression before 'spinlock_t' (access.c中)
- error: expected unqualified-id before '-' 错误
- error: expected ')' before '*' token
- error: expected a property attribute before 'strong'
- gcc 编译错误 error:expected class-name before ';' token
- expected expression before '=' token 问题
- error: expected a property attribute before 'strong'
- phonegap error: expected a property attribute before 'strong'
- error: expected '=', ',', ';', 'asm' or '__attribute__' before 'glbvar'
- error: expected class-name before '{' token
- C++构造函数初始化列表处提示出现 error: expected '{' before 'this'
- error: expected primary-expression before 'int'
- error: expected declaration specifiers or '...' before xxx(xxx是函数形参)
- UnboundLocalError: local variable 'XXX' referenced before assignment
- error: expected class-name before '{' token
- Python的UnboundLocalError: local variable 'xxx' referenced before assignment
- error: expected unqualified-id before 'delete' void delete(node* p,char a) ^
- error: expected template-name before '<' token
- error: expected unqualified-id before 'int'