为数组的指针,以不同类型的可能在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 ++?
发布评论