D
darrell.blake
I'm trying to pass an std::string to an object's constructor but I'm
getting errors. This is my code:
cout << "Enter name for Player 1: ";
string name;
getline(cin, name);
Player1 player1(name);
I get an error on the last line stating "error C2440: 'initializing' :
cannot convert from 'std::string' to 'Player'" It says that no
constructor could take the source type, or constructor overload
resolution was ambiguous.
This the constructor for my Player class:
class Player {
public:
Player(string name);
....
private:
string name;
};
Player:layer(string name) {
this->name = name;
}
I can't see what I'm doing wrong. I'm making the jump to using
std::string after using char* for years.
getting errors. This is my code:
cout << "Enter name for Player 1: ";
string name;
getline(cin, name);
Player1 player1(name);
I get an error on the last line stating "error C2440: 'initializing' :
cannot convert from 'std::string' to 'Player'" It says that no
constructor could take the source type, or constructor overload
resolution was ambiguous.
This the constructor for my Player class:
class Player {
public:
Player(string name);
....
private:
string name;
};
Player:layer(string name) {
this->name = name;
}
I can't see what I'm doing wrong. I'm making the jump to using
std::string after using char* for years.