Hi
I have a constructor for a class that takes an argument:
chessBoard(
bool StandardBoard ){
// reserve memory for the array variablesboardContents =
gcnew array<unsigned char>(64);KSCastle =
gcnew array<bool>(2);QSCastle =
gcnew array<bool>(2);whitePositions =
gcnew array<unsigned char>(16);blackPositions =
gcnew array<unsigned char>(16); //we want the board to appear empty to the program, so //we fill all the squares with the empty value for(int scrL = 0; scrL<64;scrL++)boardContents[scrL] = 255;
if(StandardBoard) //commonly, the starting layout may be required.{
//black pawns for(int scrL=8; scrL<16; scrL++)boardContents[scrL] = 6;
//white pawns for(int scrL=48; scrL<56; scrL++)boardContents[scrL] = 0;
//other pieces //rooksboardContents[0] = 9;
//blackboardContents[7] = 9;
boardContents[56] = 3;
// whiteboardContents[63] = 3;
//knightsboardContents[1] = 7;
//blackboardContents
= 7;
boardContents[57] = 1;
//whiteboardContents[62] = 1;
//bishopsboardContents[2] = 8;
//blackboardContents[5] = 8;
boardContents[58] = 2;
//whiteboardContents[61] = 2;
//queensboardContents[3] = 10;
//blackboardContents[59] = 4;
//white //kingsboardContents[4] = 11;
//blackboardContents[60] = 5;
//whiteSetupPositions();
}
}
I have no other constructor defined. I am trying to implement a routine called CopyBoard so that I can copy my class exactly (with shallow copies of the arrays) by writing chessBoard newBoard = oldboard.CopyBoard;
I started writing it simply like this (within the body of the class):
//ATTEMPT AT A COPY ROUTINE //
chessBoard CopyBoard()
{
chessBoard newBoard =
gcnew chessBoard( false ); return newBoard;}
But when I compiled it (to make sure syntax etc. I get this error:
Error 1 error C2664: 'Representations::chessBoard::chessBoard(bool)' : cannot convert parameter 1 from 'Representations::chessBoard ^' to 'bool' Representations.h 112
I also notice that Intellisense thinks that chessBoard has two constructors. One is chessBoard( ) and the other is chessBoard ( const chessBoard & ) which I assume is the default copy constructor. Neither is the constructor that I actually defined.
This problem also occurs if I try to write the copy routine outside the class body.
Hope you can help!
Fritz

Problems with constructors
Rafael Cabedo
The way you originally wrote it, you return a copy of a chessBoard object but there is no copy constructor. A copy constructor is highly recommended.
Suscuaja
That worked! Bloody obvious, too! :)
Many, many thanks!
Fritz
Johan van Toll
This throws the compile error:
Error 1 error C3699: '&' : cannot use this indirection on type 'Representations::chessBoard' Representations.h 111
Considering what I'm trying to achieve, could someone let me know how they would go about it, with some code examples
Sorry about this - one of those stupid things where you get stuck on something simple, and need another pair of eyes to point out your mistake!
Cheers
Fritz
MobilTech
Shouldn't you do:
chessBoard^ CopyBoard()
{
chessBoard^ newBoard = gcnew chessBoard( false );
return newBoard;
}