help in overloading ostream op

S

sahm

hi,
i have to create a program that will print the 52 cards in a deck using
the overloaded ostream operator. it worked fine....then i hve to create
a function that will print the cards in hand in random(5, 10).

//error it shld only have two parameters
ostream& operator<<(ostream& out, vector<Card>& deck2, vector<Card>&
hand)
{

for(unsigned int i = 0; i < hand.size(); i++)
{
int random;
random = randNum(0, 51);

//if the card is picked, don't add it in
hand,instead add another card/s in the vector
if(deck2[random].isPicked())
{
deck2[random].printCard(out);
out << endl;
int last = hand.size() - 1;
hand.push_back(hand[last]);
for(int i = last; i > deck2[random].isPicked();
i--)
{
hand[last] = hand[last - 1];
}

}

else
{
hand = deck2[random];
deck2[random].setPicked(true);
hand.printCard(out);
out << endl;
}
}
return out;
}

what shld i put in the parameters of ostream& operator<<(..) in order
to print the card in hand
 
R

Ron Natalie

sahm said:
hi,
i have to create a program that will print the 52 cards in a deck using
the overloaded ostream operator. it worked fine....then i hve to create
a function that will print the cards in hand in random(5, 10).

I think you need to define your problem better.
As you noted operator<< should only have two operands.

You should separate the generation of the hand from the deck
from outputing a hand or a single card. I suggest the following.

First write
ostream << Card;

Then using that also write
ostream << vector<Card>

Then right other functions that make the deck and hands.

I would suggest it would be easier if you actually removed the
cards from the deck after it is picked rather than maintaining
some sort of picked state. Think about the real world you're
attempting to model here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,186
Messages
2,570,998
Members
47,587
Latest member
JohnetteTa

Latest Threads

Top