是指针数组不同类型可能在C ++? [英] Are array of pointers to different types possible in c++?

查看:134
本文介绍了是指针数组不同类型可能在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 ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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