switch(player1Choice){
case object::rock: cout << ""; break;
case object::paper: cout << ""; break;
case object::scissors: cout << ""; break;
}
switch(player2Choice){
case object::rock: cout << ""; break;
case object::paper: cout << ""; break;
case object::scissors: cout << ""; break;
}
}
When compiling I get the errors "Function 'getChoice' is used but not defined in this translation unit, and cannot be defined in any other translation unit because its type does not have linkage" and "Function definition is not allowed here" for line 12 (object getChoice(string input){) and "Use of undeclared identifier 'getChoice'" for lines 17 and 18 that is (object player1Choice = getChoice(player1Input);) and (object player2Choice = getChoice(player2Input);)
Since getChoice() must be outside of main() and it returns an object, the definition of object must be outside of main() too.
getChoice() is a bad name for this function. I'd call it stringToObject() because it converts a string to an object. You will probably find that you also need an objectToString() function.
Your switch statements are nearly identical. That code should be in a function.
for ( const std::string& name : object_names )
std::cout << name << ' ' ;
Uses range-syntax that was added for the for-loop in C++11.
It is (here) equivalent to:
1 2 3 4
for ( int w=0; w < 3; ++w ) {
const std::string& name = object_names[w];
std::cout << name << ' ' ;
}
The & in declaration of 'name' tells that 'name' is a reference rather than independent variable.
Reference is an alias -- additional name that can be used to refer to existing value.