I’m very confused about making a vector to hold classes.
If I wanted to hold a bunch of data in a single vector like the example below, then have the data written in a class member function, and able to be called out and used by other functions.
Where do I stick the vector declaration? please help!
#include <vector>
class Card
{
public:
int suit;
int rank;
Card::Card(int suit, int rank);
Function();
};
vector<Card> cards;
int main()
{
}
Card::Function()
{
for loop...
Card cardz(i, i);
cards.push_back(cardz);
}
It seems to me that you’re stretching the bounds of what a
Cardobject should do. May I suggest the following layout? First defines a single card.Next, define an object which holds a
vectorof cards and manipulates them. Let’s call itDeckNow, in your
Deckclass, you can initialize the collection of cards as you see fit.