Archived

This topic is now archived and is closed to further replies.

mstein

array with initializer list

Recommended Posts

mstein    122
why wont this work, i get the following error: error C2059: syntax error : ''{ error C2334: unexpected token(s) preceding ''{''; skipping apparent function body
  
#pragma once
#include "CC_Cell.h"

class CC_Board
{
public:
	CC_Board(void);
	~CC_Board(void);

	// draw the board

	void draw(void);
private:
	CC_Cell * cells[17][13];
	int cell_map[][2] = {  //error is here

		{ 1, 2 },
		{ 3, 4 }
	};
};
  

Share this post


Link to post
Share on other sites
billybob    134
you can't define variables like that in the class, only declare them. you have to put it in the constructor

edit: btw, this isn't the initializer list , the initializer list is on the constructor:


CC_Board::CC_Board()
: Var1(0), var2(2), var3(55) // initializer list, sometimes on the line above right after CC_Board()
{
...
}


[edited by - billybob on March 8, 2003 4:10:38 AM]

Share this post


Link to post
Share on other sites
mstein    122
im glad your up late, thanks

eidt: its called initializer ??? so i just threw in list, i understand the difference, thank you again

[edited by - mstein on March 8, 2003 4:15:15 AM]

Share this post


Link to post
Share on other sites
SiCrane    11839
Actually, it is called an initializer list (See section 8.5.1 in the standard). And what occurs after the : in a constructor definition is called a mem-initializer list (12.6.2). Though it''s usually pronounced member intializer list.

int a[] = { 1, 2, 3, 4 } // initializer list
CC_Board::CC_Board() : Var1(0), var2(2), var3(55) // member initializer list

Share this post


Link to post
Share on other sites