John O' Meara
- 325
- 0
A C++ computer science book gives the following program. But my compiler reports an error; "void towersOfHanoi(int): error: reference to 'left' is ambiguous".
It {the book] has left me confused about enum. Can someone sort it out for me, please. Thanks in advance.
Code:
int lineNumber;
enum pole { left, middle, right };
void towersOfHanoi(int n, pole start, pole temporary, pole destination) {
if (n > 0) {
towersOfHanoi(n-1, start, destination, temporary);
lineNumber++;
cout << lineNumber << ". Move the top from the " << start
<< " pole to the " << destination << " pole.\n";
towersOfHanoi(n-1, temporary, start, destination);
}
}
void towersOfHanoi(int d)
{
lineNumber = 0;
towersOfHanoi(d, left, middle, right);
}
ostream& operator<<(ostream& os, pole p)
{
switch(p) {
case left: os << "left"; break;
case middle; os << "middle"; break;
case right: os << "right"; break;
}
return os;
}
int main()
{
towersOfHanoi(3);
return 0;
}