I have a struct, player, which is as follows:
struct player {
string name;
int rating;
};
I'd like to modify it such that I declare the struct with two arguments:
player(string, int)
it assigns the struct's contents with those values.
you would use the constructor, like so:
struct player {
player(const string& pName, const int& pRating) :
name(pName), rating(pRating) {} // << initialize your members
// in the initialization list
string name;
int rating;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With