On Jun 30, 10:03am, Peskov Dmitry <vamsi.kom...@gmail.com> wrote:
> class simple_class
> {
> int data;
> public:
> simple_class() {data=10;};
> simple_class(int val) : data(val){}
>
> };
>
> int main()
> {
> simple_class obj1(10); // Initializing a single object through
> single parameter constructor
> return 0;
>
> }
>
> How to initialize the values of array of simple_class objects during
> declaration through the single paramter constructor?
>
> 1 method i know is
>
> simple_class obj_array[]={5,6,10};
>
> However, I would like to know if there is any alternative way so that
> i can initialize things while declaring an array of objects ?
What is wrong with the code you showed? That is perfectly valid way
to initialize objects in an arary:
simple_class obj_array[3] = {5,6,10};
Ivan Novick
http://www.mycppquiz.com