initiliazing object array

I want to initialize an object array from another class with the default constructor, is it possible? and how?


here's what I've done, but I'm getting an error...



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include"Brisca.h";


int const total = 40;

class Deck {


private:

	Brisca deck[total];


public:

	/*default constructor*/
	Deck()
	{
		deck[total]= 
		{
			{'O',1,11, },{'O',2,0, },{'O',3,10, },{'O',4,0, },{'O',5,0, },{'O',6,0, },{'O',7,0, },{'O',10,2, },{'O',11,3, },{'O',12,4, },
			{'E',1,11, },{'E',2,0, },{'E',3,10, },{'E',4,0, },{'E',5,0, },{'E',6,0, },{'E',7,0, },{'E',10,2, },{'E',11,3, },{'E',12,4, },
			{'C',1,11, },{'C',2,0, },{'C',3,10, },{'C',4,0, },{'C',5,0, },{'C',6,0, },{'C',7,0, },{'C',10,2, },{'C',11,3, },{'C',12,4, },
			{'B',1,11, },{'B',2,0, },{'B',3,10, },{'B',4,0, },{'B',5,0, },{'B',6,0, },{'B',7,0, },{'B',10,2, },{'B',11,3, },{'B',12,4, }
		};
	}
};
Would be helpful if you didnt keep the error message a secret from us. Could you copy paste it?

Error (active) no instance of constructor "Brisca::Brisca" matches the argument list
You can't initialize an array like that after declaring it.

Edit:

If your compiler supports c++11 You can do this -
1
2
3
4
5
6
7
class Deck {

Brisca deck[total];
Deck() : deck {'O', 1, 11, ...} { }

// http://stackoverflow.com/questions/11610338/how-to-initialise-a-member-array-of-class-in-the-constructor
}
Last edited on
Topic archived. No new replies allowed.