字符数组的初始化字符串太长。在Xcode
问题描述:
中将编译源设置为Objective-C++之后,我创建了一个新的单个视图项目来测试它。在我的ViewController.m里面是代码:字符数组的初始化字符串太长。在Xcode
我不知道为什么当我将我的编译源设置为ObjectiveC++时,它给了我这个错误? 初始化串为字符数组太长
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.
}
答
的C-字符串文字"12"
需要3个字符,1
,2
,和空终止。
如果要初始化2 char数组,这样做:
静态常量字符_basex2 [2] = { '1', '2'};
那么当编译源设置为“根据文件类型”时,编译器怎么会不给我一个错误? – mskw 2013-04-11 16:20:27
@mskw - 什么是文件后缀? – 2013-04-11 16:22:00
后缀是.m – mskw 2013-04-11 16:22:31