Array of structs w/constructor

I can't seem to remember everything I should about constructors. I'm looking for a way to create an array of structs, using a constructor. My code should explain what I would like to do, and my question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct myStruct
{
private:
	int structInt1, structInt2;
public:
	myStruct::myStruct(int int1, int int2)
	{
	    structInt1 = int1 * int2;
            structInt2 = int1 / int2;
	};
};


int main()
{
       myStruct myStructArray[10] =
       {
             // Any way to initialize these ten items using the existing constructor?
            //Maybe an additional constructor?
       }
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
myStruct myStructArray[10] =
{
	myStruct(42,54),
	myStruct(13,10),
	myStruct(6,9),
	myStruct(3,14),
	myStruct(2,72),
	myStruct(1,62),
	myStruct(0,0),
	myStruct(0,1),
	myStruct(1,0),
	myStruct(1,1)
};
Yep. Worked like a charm. Thanks.
Topic archived. No new replies allowed.