-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec_of_objs.cpp
More file actions
46 lines (35 loc) · 1.12 KB
/
Copy pathvec_of_objs.cpp
File metadata and controls
46 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
*/
#include <iostream>
#include <vector>
#include <algorithm> // std::sort
#include "Player.h"
using std::cout;
bool sortDesc(Player a, Player b) {
return (a.getCharisma()>b.getCharisma()); }
int main()
{
Player p001("Amwrath", 10,11,12,13);
Player p002("Xenia", 15,11,15,16);
Player p003("Grendel", 14,21,12,8);
Player p004("Galen", 16,10,17,14);
std::vector<Player> playersVec;
// move the objects into the vector (not a copy)
playersVec.push_back(std::move(p001));
playersVec.push_back(std::move(p002));
playersVec.push_back(std::move(p003));
playersVec.push_back(std::move(p004));
// sort vector according to players' charisma
std::sort(playersVec.begin(), playersVec.end(), sortDesc);
// print vector elements
cout << "Players sorted by charisma:\n";
for (auto& e: playersVec)
e.listPlayer();
cout << "\n";
// pop from the vector the player with lowest charisma
playersVec.pop_back();
cout << "Player with lowest charisma dropped from vector:\n";
// print vector elements
for (auto& e: playersVec)
e.listPlayer();
}