Witam. Mam problem z enum. W mojej klasie wszystkie składni(name, surname) przechodzą z funkcji enter_data() do show(). Jednak problem jest z enumem, który nie chce przejść i nie mam pojęcia czemu.
#include<iostream>
#include <string>
#include <process.h>
#include <list>
#include <cstddef>
#include <fstream>
#include<cstdlib>
#include <sstream>
using namespace std;
enum POSSITION {
Goalkeeper=1,
Defender=2,
Helper=3,
Attacker=4
};
class Player {
string name;
string surname;
POSSITION posOnThePitch;
public:
void enter_data() {
cout << "\nName: ";
cin >> name;
cout << "Surname: ";
cin >> surname;
cout << "\n\n\nSelect Possition:\n";
cout << "1.Goalkeeper" << endl;
cout << "2.Defender" << endl;
cout << "3.Helper" << endl;
cout << "4.Attacker\n\n\n" << endl;
int temp_possition;
cin >> temp_possition;
POSSITION posOnThePitch = static_cast<POSSITION>(temp_possition);
}
string show()
{
string temp;
cout << "xd" << endl;
temp = name + " " + surname + " " + posOnThePitch;
cout << temp << endl;
return temp;
}
};
int main()
{
Player p1;
p1.enter_data();
p1.show();
system("pause");
}// main
Problem pojawia się dokładnie w tej linijce:
temp = name + " " + surname + " " + posOnThePitch;
Name oraz surname ładnie się wyświetlają, ale gdy dodam posOnThePitch to nie kompiluje. Na pewno dałoby się to jakoś rozwiązać poprzez przeciążenie operatora, ale ja chcę normalnie.
show()
niepotrzebnie zwraca łańcuch. Poza tym jej nazwa nie sugeruje zwracania wyniku.