Author: José Carlos
Date: 01:10:14 05/12/99
Go up one level in this thread
On May 12, 1999 at 01:01:00, Dave Gomboc wrote:
>I am taking a quick look at Tom's Simple Chess Program. Here's a snippet:
>
>/* the initial board state */
>
>int init_color[64] = {
> 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0
>};
>
>Now, imagine you are trying to do this in OO-style. Say you have some class
>State, and you want this to be inside of it.
>
>So (in C++):
>
>class State {
>
>public:
> // stuff
>
>protected:
> // more stuff
>
> int init_color[64] = {
> 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 6, 6, 6, 6, 6, 6, 6, 6,
> 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, 0, 0, 0
> };
>};
>
>This, however, does not compile. (MSVC 6.0 reports error C2059, a syntax error
>on the '{'. Presumably, the array initialization isn't allowed.)
>
>Ideally, this array would be declared static and const as well.
>What is wrong here? How can it be corrected?
>
>Dave
I have a header file where I put all of this definitions, so I've never tried
what you want to do. I think it's more clear to initialise these arrays apart
from the class definition, and then, assigning them to the apropiate class
members in the constructor, because there is where the object is realy created.
José C.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.