[英]How can I write the equivalent dynamically-allocated nested Vectors from C++ to Obj-C?
We're porting over some C++ .h to Objective C .h files. 我们正在将某些C ++ .h移植到Objective C .h文件。
Here is a sample of the C++ code we're trying to port over for our class. 这是我们尝试为我们的类移植的C ++代码示例。
std::vector< std::vector< int > > D2DMap;
std::vector< std::vector< int > > D3DMap;
We have yet to be successful in declaring an equivalent in Obj-C. 我们尚未成功声明Obj-C中的等效项。
NSMutableArray *D2DMap = [[NSMutableArray alloc] init];
NSMutableArray *inner = [[NSMutableArray alloc] init];
[inner addObject:[NSNumber numberWithInt:someInt]];
[D2DMap addObject:inner];
But we know this is wrong because it is not dynamic at run time. 但是我们知道这是错误的,因为它在运行时不是动态的。
You could use Objective-C++. 您可以使用Objective-C ++。
If you don't want to use Objective-C++, you're sort of out of luck. 如果您不想使用Objective-C ++,那么您会很不走运。 There is no non-dynamically-typed array in the Cocoa library.
Cocoa库中没有非动态类型的数组。 You could hack together a solution involving malloc and other generally disgusting things, but I'd recommend against it.
您可以一起解决涉及malloc和其他通常令人作呕的事情的解决方案,但是我建议不要这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.