To define the constructor inline use
1 2 3 4 5
|
public class Card {
public:
Card(string v, string s) : value(v), suit(s) {}
string value,suit;
};
|
to define it outside of the class
1 2 3 4 5 6 7 8 9
|
public class Card {
public:
Card(string v, string s);
string value,suit;
};
Card::Card(string v, string s) : value(v), suit(s)
{
}
|
(I renamed your parameters so they were different to the member variable names.)
As you have declared your vector as
vector<Card> deck;
You have to push_back like this (without a new)
deck.push_back(Card(value[j],suit[i]));
If you want to push newed cards, you need to define the vector (to store Card pointers) as
vector<Card*> deck;
BUT then you'd have to remember to delete all the cards later, which is unnecessarily hard work for such a small class.
or copy the / again inside |
Not sure I get this. Don't see any other problems.
AND you could swap your string array for a char const * const array, as it stand.
char const * const hs[] = {"S","H","C","D"};
Swapping to use a char array would need a little more work. And I would prob. do that in conjunction with a change of member variable type.
Andy
P.S. Using a string to store a single char is a bit overkill. So unless you plan to use "King", "Queen", etc. in the future, you might want to adjust your member's types.