![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 2
| array initialization error The error I'm getting is: Code: cannot convert ‘<brace-enclosed initializer list>’ to ‘char’ in assignment Code: #include <iostream>
using namespace std;
class turn {
public:
turn();
~turn();
void display();
void getpick( char player );
void change();
private:
char board[3][3];
void valid();
};
turn::turn() {
board[3][3] = {
{ 'a' , 'b' , 'c' },
{ ' ' , ' ' , ' ' },
{ ' ' , ' ' , ' ' } };
}
|
| FlyingShoes12 is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Unfortunately, you can initialise member arrays like that. You should assign the values "manually".
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is offline | |
| | #3 |
| Registered User Join Date: Apr 2006
Posts: 1,193
| You can't assign to an array. You have to use a loop. The brace syntax is only valid where you declare the array, and you cannot use it in objects. This will be fixed in C++0x.
__________________ It is too clear and so it is hard to see. A dunce once searched for fire with a lighted lantern. Had he known what fire was, He could have cooked his rice much sooner. |
| King Mir is offline | |
| | #4 | |
| The larch Join Date: May 2006
Posts: 3,082
| You can't assign arrays. Besides, you are even attempting to assign a whole array to a single element in the board array, which also happens to be out of bounds. With C++0x, you should be able to use the initialization list like this: Code: turn::turn():
board
{
{ 'a' , 'b' , 'c' },
{ ' ' , ' ' , ' ' },
{ ' ' , ' ' , ' ' }
}
{
}
Code: turn::turn()
{
char board_init[3][3] = {
{ 'a' , 'b' , 'c' },
{ ' ' , ' ' , ' ' },
{ ' ' , ' ' , ' ' }
};
std::copy(&board_init[0][0], &board_init[3][3], &board[0][0]);
}
__________________ I might be wrong. Quote:
Last edited by anon; 11-14-2009 at 11:11 AM. | |
| anon is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| what am I missing? (Program won't compile) | steals10304 | C Programming | 3 | 08-25-2009 03:01 PM |
| Making C DLL using MSVC++ 2005 | chico1st | C Programming | 26 | 05-28-2008 01:17 PM |
| load gif into program | willc0de4food | Windows Programming | 14 | 01-11-2006 10:43 AM |
| Problem with Visual C++ Object-Oriented Programming Book. | GameGenie | C++ Programming | 9 | 08-29-2005 11:21 PM |
| UNICODE and GET_STATE | Registered | C++ Programming | 1 | 07-15-2002 03:23 PM |