关于在c ++中改组数组的快速问题
出于某些原因,我的牌在我洗牌之前有正确的数字和套装。在我做完之后......卡片上的所有数值都变为1,套装消失了......最奇怪的事情。
任何帮助都会很棒!
// ViewController.swift
let loginOperation = LogInOperation(
mail: "mail@example.com",
password: "123123",
completion: { op in
// parsedObject would be the user's info
print(op.parsedObject?)
}, error: { error in
print(error.localizedDescription)
}
)
OperationQueue.addOperation(loginOperation)
一些输出
const int Deck::RANKS[13] = {2,3,4,5,6,7,8,9,10,11,12,13,14};
const char Deck::SUITS[4] = {'H','D','C','S'};
Card cards[52];
int cardNum = 0;
Deck::Deck() : size(0)
{
cardNum = 0;
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 4; j++)
{
cards[size] = Card(RANKS[i],SUITS[j]);
cout << "Card Created with " << RANKS[i] << " and " << SUITS[j] << "\n";
size++;
}
}
shuffle();
for(int x = 0; x < 52; x++)
{
Card c = cards[x];
cout << "Card Contains " << c.value << " and " << c.suit << "\n";
}
}
Deck::~Deck() {}
void Deck::shuffle()
{
size = MAX_SIZE;
std::random_shuffle(begin(cards), end(cards));
}
//关闭后
Card Created with 13 and C
Card Created with 13 and S
Card Created with 14 and H
Card Created with 14 and D
Card Created with 14 and C
Card Created with 14 and S
Card.cpp
Card Contains 1 and
Card Contains 1 and
Card Contains 1 and
Card Contains 1 and
答案 0 :(得分:4)
错误在这里。您正在为自己分配参数。
Card::Card(int value, char suit)
{
value = value;
suit = suit;
}
您可以使用此关键字
Card::Card(int value, char suit)
{
this->value = value;
this->suit = suit;
}
但是要做的就是使用评论中所述的列表初始化。