I'm trying to instantiate an array of a class where the constructor takes two arguments, and initialize it in the same line.
Conceptually, I want to do something like this:
foo::foo (int A, int B = 10)
{
V1 = A;
V2 = B;
}
foo Myfoo[3] = { (1, 100), (2, 300), (5, 100) };
// what I _don't_ want to do is create individual objects like this:
// foo Myfoo1(1, 100);
// foo Myfoo2(2, 300);
// foo Myfoo3(5, 100);
What I found is that when the constructor is called the arguments are not as expected. The B argument always shows up as the default value of 10. Just in tinkering I threw in additional arguments in the array initialization.
foo Myfoo[3] = { (0, 1, 100), (2, 300, 0), (0, 5, 100, 0) };
To my surprise it compiled without error, but I didn't pursue this too far, because it didn't make sense to me - but I was able to affect the problem
Does anyone have an idea on how I should code this? I've already worked around the problem but I'm curious how it should be done properly.