Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- using namespace std;
- class Person {
- public:
- Person() : id(0), salary(0), name("-") {
- puts("Call Person()");
- };
- Person(const int id, const double salary, const string& name)
- : id(id), salary(salary), name(name) {
- puts("Call Person(const int& id, const double& salary, const string& name)");
- ++copying;
- }
- Person(const Person& p)
- : id(p.id), salary(p.salary), name(p.name) {
- puts("Call Person(const Person& p)");
- ++copying;
- }
- ~Person() {
- puts("Call ~Person()");
- if (this->id) cout << "\t" << *this << '\n';
- cout << "\tCopying: " << copying << '\n';
- cout << "\tMoving: " << moving << '\n';
- cout << "\tDestruction: " << ++destruction << '\n';
- }
- // Закомментировать два конструктора и перекомпилировать
- Person(int&& id, double&& salary, string&& name)
- : id(id), salary(salary), name(move(name)) {
- puts("Call Person(int&& id, double&& salary, string&& name)");
- ++moving;
- }
- Person(Person&& p)
- : id(p.id), salary(p.salary), name(move(p.name)) {
- puts("Call Person(Person&& p)");
- ++moving;
- }
- private:
- int id;
- double salary;
- string name;
- static unsigned copying;
- static unsigned moving;
- static unsigned destruction;
- friend ostream& operator<<(ostream& out, const Person& p) {
- return out << p.id << ' ' << left << setw(16) << p.name << ' ' << p.salary;
- }
- };
- unsigned Person::copying = 0U;
- unsigned Person::moving = 0U;
- unsigned Person::destruction = 0U;
- Person sidorov() {
- return { 28042, 128304.02, "Sidorov S. P."s };
- }
- Person antonov() {
- return { 28063, 173589.13, "Antonov G. N." };
- }
- int main() {
- const char* s = "--------------------------------";
- vector<Person> persons;
- Person ivanov{ 28074, 147235.26, "Ivanov I. G."s };
- Person petrov{ 28055, 152477.29, "Petrov A. V." };
- persons.emplace_back(ivanov); // 1
- persons.emplace_back(petrov); // 2
- puts(s);
- persons.emplace_back(antonov()); // 3
- persons.emplace_back(sidorov()); // 4
- puts(s);
- persons.emplace_back(28002, 140038.07, "Gavrilov A. A."s); // 5
- persons.emplace_back(28104, 122033.48, "Tarasov S. Z."); // 6
- puts(s);
- persons.push_back({ 28127, 104305.07, "Stepanov D. O."s }); // 7
- persons.push_back({ 28099, 137011.22, "Prokhorov F. I." }); // 8
- puts(s);
- int id = 28111;
- double salary = 161304.58;
- string zakharov = "Zakharov U.L.";
- persons.push_back({ id, salary, zakharov }); // 9
- persons.emplace_back(id, salary, zakharov); // 9
- puts(s);
- Person Zakharov{ id, salary, zakharov }; // 9
- persons.push_back(Zakharov);
- persons.emplace_back(Zakharov);
- puts(s);
- Person empty; // 10
- puts(s);
- for (const auto& record : persons) cout << record << '\n';
- puts(s);
- empty.~Person();
- puts(s);
- system("pause > nul");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement