简体   繁体   English

如何将等效的动态分配嵌套向量从C ++写入Obj-C?

[英]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.

相关问题 在C ++中删除后,为什么我不能重用动态分配的数组的名称? - Why can't I reuse the name of a dynamically-allocated array after I delete it in C++? 有没有办法在 C++ 中静态初始化动态分配的数组? - Is there a way to statically-initialize a dynamically-allocated array in C++? OBJ-C中等效的C ++图形 - C++ Graphics Equivalent In OBJ-C C ++中动态分配内存的初始值 - Initial Value of Dynamically-Allocated Memory in C++ 在没有Obj-C代码的情况下,如何在c ++中将NSString转换为CString? - How can I convert an NSString to a CString in c++ without Obj-C code? C ++的obj-c委托模式是什么? - What's the C++ equivalent of the obj-c delegate pattern? C++ -- 从二进制文件中读取动态分配的向量 - C++ -- reading dynamically allocated vectors from a binary file C ++清除指向动态分配对象的指针向量导致异常? - C++ Clearing vector of pointers to dynamically-allocated object causes exception? 使用动态分配的 arrays 导致来自代码分析的 C6386 缓冲区溢出警告 - Using dynamically-allocated arrays causes C6386 Buffer Overrun warning from Code Analysis Java等效于C ++中动态分配的数组 - java equivalent of dynamically allocated arrays in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM