how can i make array of objects for this class ?

class A
{
Public:
A (int);
A(int,int);
int get (int,int);




};
Since you do not have any data members in the class, what do you want the constructors to do?
A my_array_of_objects_for_this_class[10];
Last edited on
You can not create an array of this class without initializers because the class has no the default constractor.
So you can write something as

A a[] = { { 1 }, { 2 }, { 3 }, { 4 }, { 5 } }; // if the compiler supports C++ 11
or

A a[] = { A( 1 ), A( 2 ), A( 3 ), A( 4 ), A( 5 ) }; // if the compiler does not support C++ 11

Or even the following way irrespective of whether the compiler supports C++ 11 or not.:)

A a[] = { 1, 2, 3, 4, 5 };
Last edited on
The last example will not work if the constructor A (int); is declared as explicit.
Last edited on
If you want to use the second constructor with two parameters then there are two possibilities

A a[] = { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 } }; // if the compiler supports C++ 11 or

A a[] = { A( 1, 1 ), A( 2, 2 ), A( 3, 3 ), A( 4, 4 ), A( 5, 5 ) }; // if the compiler does not support C++ 11
Last edited on
Topic archived. No new replies allowed.