I created a new single view project to test this. Inside my ViewController.m here is the code:
I'm not sure why when I set my compile sources as ObjectiveC++ it gives me this error? initializer-string for char array is too long
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.
}
The C-string literal "12"
takes 3 characters, 1
, 2
, and the null terminator.
If you want to initialize the 2 char array, do this:
static const char _basex2[2] = { '1', '2' };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.