call by reference using pointers
-
does anyone know how to write this as call by constant reference using pointers?? here is what ive been trying to do: int CComputer::CheckForMoves(const CBoard& rBoard, int depth) { CBoard Board = rBoard; <-- but using pointers instead of reference } so i can call it in the main function like this: CheckForMoves(pBoard,1); where pBoard is a pointer of CBoard is there a way i can do something like that without getting any syntax errors???? cause i have tried all sorts of stuff like that but the compiler wont allow me to do so.... anyways, thanx for you help :) John
-
does anyone know how to write this as call by constant reference using pointers?? here is what ive been trying to do: int CComputer::CheckForMoves(const CBoard& rBoard, int depth) { CBoard Board = rBoard; <-- but using pointers instead of reference } so i can call it in the main function like this: CheckForMoves(pBoard,1); where pBoard is a pointer of CBoard is there a way i can do something like that without getting any syntax errors???? cause i have tried all sorts of stuff like that but the compiler wont allow me to do so.... anyways, thanx for you help :) John
CheckForMoves( *pBoard,1) ;//main fn int CCtrlResize::CheckForMoves(const CBoard& rBoard, int depth) { const CBoard& Board = rBoard; //Init to a const referece, because thats what it is return 0 ; }
-
does anyone know how to write this as call by constant reference using pointers?? here is what ive been trying to do: int CComputer::CheckForMoves(const CBoard& rBoard, int depth) { CBoard Board = rBoard; <-- but using pointers instead of reference } so i can call it in the main function like this: CheckForMoves(pBoard,1); where pBoard is a pointer of CBoard is there a way i can do something like that without getting any syntax errors???? cause i have tried all sorts of stuff like that but the compiler wont allow me to do so.... anyways, thanx for you help :) John
What I know that is not allowed! You have to use either references or pointers. ------------------------------------ Rickard Andersson, Suza Computing ICQ#: 50302279 I'm from the winter country SWEDEN! ------------------------------------
-
CheckForMoves( *pBoard,1) ;//main fn int CCtrlResize::CheckForMoves(const CBoard& rBoard, int depth) { const CBoard& Board = rBoard; //Init to a const referece, because thats what it is return 0 ; }
Well, I guess I got it wron then! ------------------------------------ Rickard Andersson, Suza Computing ICQ#: 50302279 I'm from the winter country SWEDEN! ------------------------------------
-
does anyone know how to write this as call by constant reference using pointers?? here is what ive been trying to do: int CComputer::CheckForMoves(const CBoard& rBoard, int depth) { CBoard Board = rBoard; <-- but using pointers instead of reference } so i can call it in the main function like this: CheckForMoves(pBoard,1); where pBoard is a pointer of CBoard is there a way i can do something like that without getting any syntax errors???? cause i have tried all sorts of stuff like that but the compiler wont allow me to do so.... anyways, thanx for you help :) John
Pointers and references are not the same thing, you can't use both at the same time*. You can either write:
int CComputer::CheckForMoves(const CBoard& rBoard, int depth)
{
const CBoard& Board = rBoard;
const CBoard* p = &rBoard;
}which passes the param as a reference, or:
int CComputer::CheckForMoves(const CBoard* pBoard, int depth)
{
const CBoard* p = pBoard;
const CBoard& refBoard = *pBoard;
}which passes a pointer. * Note for C++ experts: yes I know you can have a reference to a pointer; I didn't mention that above because it would be unnecessarily confusing. --Mike-- Best score on the mini-putt game: 27 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.
-
Pointers and references are not the same thing, you can't use both at the same time*. You can either write:
int CComputer::CheckForMoves(const CBoard& rBoard, int depth)
{
const CBoard& Board = rBoard;
const CBoard* p = &rBoard;
}which passes the param as a reference, or:
int CComputer::CheckForMoves(const CBoard* pBoard, int depth)
{
const CBoard* p = pBoard;
const CBoard& refBoard = *pBoard;
}which passes a pointer. * Note for C++ experts: yes I know you can have a reference to a pointer; I didn't mention that above because it would be unnecessarily confusing. --Mike-- Best score on the mini-putt game: 27 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan and Jamie Salé.
-
does anyone know how to write this as call by constant reference using pointers?? here is what ive been trying to do: int CComputer::CheckForMoves(const CBoard& rBoard, int depth) { CBoard Board = rBoard; <-- but using pointers instead of reference } so i can call it in the main function like this: CheckForMoves(pBoard,1); where pBoard is a pointer of CBoard is there a way i can do something like that without getting any syntax errors???? cause i have tried all sorts of stuff like that but the compiler wont allow me to do so.... anyways, thanx for you help :) John
Try
CheckForMoves(*pBoard,1)
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
Try
CheckForMoves(*pBoard,1)
. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo