class Person
1: //vector_emplace.cpp
3: #include <iostream>
4: #include <string>
5: #include <vector>
6: #include <algorithm>
7: using namespace std;
9: class Person
10: {
11: public:
12: Person(string name, int age)
13: {
14: this->name = name;
15: this->age = age;
16: };
17: string getName() {return name;}
18: int getAge() {return age;}
20: private:
21: string name;
22: int age;
23: };
25: int main()
26: {
27: vector<Person> v;
28: v.push_back(Person("John", 23));
29: v.emplace_back("John", 23);
30: cout << v.at(0).getName() << " " << v.at(0).getAge() << endl;
31: }