Skip to main content
GameDev.net gamedev.net
🔒 Locked

array with initializer list

Started by mstein Mar 8, 2003 at 2:59 AM 2 replies 250+ views
Original Post
mstein
mstein
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 }
	};
};
  
billybob
billybob
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]
mstein
mstein
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]
SiCrane
SiCrane
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.