I am trying to initialize array of objects with the same value
class A
{
A(int a1)
{
var1 = a1;
}
var1;
}
int main(void)
{
// I want to initialize all the objects with 5 without using an array
A *arr = new A[10](5); // How to use the constructor to do something like this
return 0;
}
As i want to pass the same value to all the objects, is there a way to avoid using an array. i.e. I want to avoid doing the following:
A *arr = new A[10]{5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
intarray, how about a simplememset()call?std::arraywhich has afillfunction?