Author: David Rasmussen
Date: 03:48:48 01/08/03
Go up one level in this thread
On January 08, 2003 at 03:22:17, Joshua Haglund wrote:
I am not even going to begin summing up all the problems there is with this. I
suggest you learn more about C++ before you try to make a chess engine. I
suggest you read "Accelerated C++" by Koenig and Moo, one of the very best C++
books out there.
But read below:
>#include <iostream>
>#include <string>
>using namespace std;
>
>void getMoves(string);
>
Here you are declaring a function getMoves which takes a string.
>int main() {
>
>string moves[31] = {"e2e4", "e2e3", "d2d4", "d2d3",
> "c2c4", "c2c3", "b2b4", "b2b3",
> "g2g3", "g2g4", "a2a3", "a2a4",
> "f2f3", "f2f4", "h2h3", "h2h4",
> "e3e4", "d3d4", "c3c4", "a3a4",
> "b3b4", "f3f4", "g3g4", "h3h4",
> "e4e5", "e5e6", "e6e7", "e7e8R",
> "e7e8Q", "e7e8B", "e7e8N"};
>
>getMoves(moves[31]);
>
Here you are calling a function called getMoves that takes a string. Although,
you are calling it with moves[31] which is undefined. The last valid entry of
your array is moves[30].
string moves[31] = ...
declares an array of 31 elements, from element 0 to element 30. So the call is
wrong anyway.
>
>
>return 0;
>}
>
>void getMoves(string m[31])
Here you are declaring and defining a function called getMoves which takes an
array of strings. This function is not called from anywhere.
>{
>
>
>cout << m[31] << endl;
>
Here you are streaming out the 31th element of the array you took as an
argument, which only had 31 elements, from 0-30, that is, it is undefined.
>}
>
You have still not _defined_ the function you _declared_ above, the one that
took a string. You have only defined another totally unrelated function that
took an array of string.
>I get this error. I don't know what this means.
>Is this error saying it's not possible to pass the string by value?? Hmmm
>
The linker is complaining that you declared a function that took a string, you
called this function, but you never defined it, or linked with something that
defined it.
In summary:
You declared a function that took a string, called it, but never defined it.
Instead you defined a function that took an array of string, which you never
used. The simplest way of getting your code to compile is to change the
void getMoves(string m[31])
to
void getMoves(string m)
now it compiles, although it's probably not doing what you thought it would
(because it's undefined).
So change also
cout << m[31] << endl;
to
cout << m << endl;
and the program probably behaves as you intended.
I really suggest you read up on C++ before making a chess engine:
http://www.acceleratedcpp.com/
/David
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.