如何改組std :: vector?我正在尋找一種通用的,可重用的方式來改變std::vectorC ++中的一個。這就是我目前的做法,但我認為它不是很有效,因為它需要一個中間數(shù)組,它需要知道項目類型(在這個例子中是DeckCard):srand(time(NULL));cards_.clear();while (temp.size() > 0) {
int idx = rand() % temp.size();
DeckCard* card = temp[idx];
cards_.push_back(card);
temp.erase(temp.begin() + idx);}
- 3 回答
- 0 關(guān)注
- 413 瀏覽
添加回答
舉報
0/150
提交
取消