使用模板C ++进行动态内存分配 [英] dynamic memory allocation with a template c++

查看:90
本文介绍了使用模板C ++进行动态内存分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在寻找一种使用模板来执行c#列表功能的方法
我不需要完整的代码,因为我有一本古老的C ++书,上面有一个例子
在具有int但与c#列表不同的动态mmemory中.

感谢您的回答.

Hi all,
I am looking for a way to use template to do what the c# list does
I don''t need complete code becouse I got a old c++ book that does a example
On dynamic mmemory with an int but not like the c# list.

Thanks for the answers.

推荐答案

C ++有什么问题
What''s wrong with the C++ list[^]?


如果要使用C ++列表,请使用std :: list.句号结束,故事结束,除非您有使其不适合的要求(即您遇到性能问题).

从您所说的内容来看,我不确定您是否知道自己的要求-也许如果您能更清楚地说明这些要求,那么有人可以为您提供解决问题的方法.

干杯,

Ash
If you want a list in C++ then use std::list. Full stop, end of story UNLESS you''ve got a requirement that makes it unsuitable (i.e. you''ve a performance problem).

From what you''ve said I''m not sure you know what your requirements are - perhaps if you could explain them a bit clearer someone could offer you a solution to your problem.

Cheers,

Ash


我看到您的要求难以捉摸.您需要使用可以动态分配元素的模板.但是数据类型呢?您是否希望通过容器(例如list)分配它,或者只是将引用/指针放在列表中,然后自己管理内存.

另一方面,也不清楚是否使用/clr进行编译.您是否在尝试/尝试混合托管和非托管内容?

您可能想使用STL/CLR列表,向量,它们与具有相同名称的STL容器类最相似.
I see your requirement is elusive. You need to use template, that can dynamically allocated elements. But what about data type? Do you want it to be allocated by container (like list), or you just put references/pointers to the list, and manage the memory yourself.

On the other side, it is also unclear if you are compiling with /clr or not. Are you attempting/trying to mix managed and unmanaged stuff?

You may like to use STL/CLR list, vector, which are mostly similar to STL''s container classes with same name.


这篇关于使用模板C ++进行动态内存分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆