1

我创建了一个新的单视图项目来测试它。在我的 ViewController.m 里面是代码:

我不确定为什么当我将编译源设置为 ObjectiveC++ 时会出现此错误?char 数组的初始化字符串太长

static const char _basex[3] = "12"; <-This is always ok
static const char _basex2[2] = "12"; <-Gives the initializer error when compiler set to Objective-C++

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
4

1 回答 1

4

C 字符串文字"12"采用 3 个字符、12和空终止符。

如果要初始化 2 char 数组,请执行以下操作:

静态 const char _basex2[2] = { '1', '2' };

于 2013-04-11T16:19:25.660 回答