#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
class klasa {
public:
static int total;
int ilosc;
klasa(int n) : ilosc(n) {
std::cout << "created with " << ilosc << "\n";
total += ilosc;
};
klasa(const klasa& drugi) {
std::cout << "copy created with " << ilosc << "\n";
ilosc = drugi.ilosc;
total += ilosc;
};
klasa& operator=(const klasa& drugi) {
std::cout << "assigned with " << ilosc << "\n";
total -= ilosc;
ilosc = drugi.ilosc;
total += ilosc;
return *this;
};
~klasa() {
std::cout << "deleted with " << ilosc << "\n";
total -= ilosc;
};
};
int klasa::total = 0;
int main() {
vector<klasa> vec;
vec.reserve(310);
int suma = 0;
for (int i = 100; i <= 500; i += 100) {
suma += i;
vec.emplace_back(i);
}
cout << "Suma wrzuconych elementow: " << suma << " Rozmiar vectora: " << vec.size() << endl;
cout << "klasa::total: " << klasa::total << endl;
cout << "before erase.. \n";
for (const auto& x : vec)
std::cout << x.ilosc << "\n";
vec.erase(vec.begin(), vec.begin() + 2);
cout << "after erase.. \n";
for (const auto& x : vec)
std::cout << x.ilosc << "\n";
cout << "vec.size() = " << vec.size() << endl;
cout << "klasa::total = " << klasa::total << endl;
return 0;
}