Reputation: 45921
I'm developing an iOS application with latest SDK.
I have an Objective-C++
class with these two properties:
@interface MyClass : NSObject
@property (nonatomic) int* road;
@property (nonatomic) int* cars;
...
@end
And inside init
method this:
_road = new int[16] (0);
_cars = new int[16] (0);
But I get this error: Array 'new' cannot have initialization arguments
.
Reading this tutorial they said that I can initialize them that way.
How can I initialize those variables?
Upvotes: 0
Views: 423
Reputation: 81868
ISO C++ does not allow to specify a constructor parameter. The tutorial you linked might refer to a language extension not available in clang.
Upvotes: 1
Reputation: 2389
To fix a problem use such code:
_road = new int[16] ();
_cars = new int[16] ();
It initialises all members of arrays to default value.
Upvotes: 2