与参数和数组对象 [英] Objects with arguments and array
问题描述
有没有在C ++的方式在哪里对象增加的说法,那么,用一个数组,如:
Is there a way in C++ where an objects has argument added upon it, with an array such as:
int x = 1;
int y = 2;
Object myObject( x, y )[5]; // does not work
我希望我可以把参数为对象,同时创造的这些对象的5阵列,没有人知道如何? ,是有bteter办法?
I was hoping that I could put arguments into the object, while creating an array of 5 of these objects, does anyone know how? and is there a bteter way?
推荐答案
在构建在C ++对象只能除非您使用显式的数组初始化语法使用的默认构造函数的数组:
When constructing an array of objects in C++ only the default constructor can be used unless you're using the explicit Array initialization syntax:
Object myObject[5] = { Object( x, y ),
Object( x, y ),
Object( x, y ),
Object( x, y ),
Object( x, y ) }
下面是关于这个C ++ FAQ一些有用的信息:
Here's some good information from the C++ FAQ about this:
<一个href=\"http://www.parashift.com/c%2B%2B-faq-lite/ctors.html#faq-10.5\">http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.5
这篇关于与参数和数组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!