是指针数组不同类型可能在C ++?

编程入门 行业动态 更新时间:2024-10-18 14:22:48
本文介绍了是指针数组不同类型可能在C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为数组的指针,以不同类型的可能在C ++?例如有请)

Are array of pointers to different types possible in c++? with example please)

推荐答案

C ++是C,更多的东西。所以,如果你想这样做的C方式,如上你只要把空指针数组

C++ is C with more stuff. So if you want to do it the C way, as above you just make an array of void pointers

void *ary[10]; ary[0] = new int(); ary[1] = new float();

DA。

如果你想要做的事情了面向对象的方法,那么您要使用的集合,并且拥有所有你将要添加到集合中的事情,从可以添加到集合中的相同的基本对象类派生。在java中这是对象,C ++没有内置的基本对象,但是你用任何集合库将有这样的,你也可以继承的东西。

If you want to do things the object oriented way, then you want to use a collection, and have all the things you going to be adding to the collection derive from the same base object class that can be added to the collection. In java this is "Object", C++ has no base object built in, but any collection library you use will have such a thing that you can subclass.

更多推荐

是指针数组不同类型可能在C ++?

本文发布于:2023-07-31 07:42:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256793.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能在   数组   指针   不同类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!