mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-10-28 11:10:38 +01:00
rzeczy
This commit is contained in:
45
uczelnia/2_semestr/programowanie/laby/lab8/licznik.cpp
Normal file
45
uczelnia/2_semestr/programowanie/laby/lab8/licznik.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
class Licznik {
|
||||
int wartosc;
|
||||
|
||||
public:
|
||||
Licznik(int wartosc) : wartosc(wartosc) {}
|
||||
Licznik() : wartosc(0) {}
|
||||
Licznik &operator++() {
|
||||
wartosc++;
|
||||
return *this;
|
||||
}
|
||||
Licznik operator++(int) {
|
||||
Licznik stary = *this;
|
||||
++wartosc;
|
||||
return stary;
|
||||
}
|
||||
Licznik &operator--() {
|
||||
wartosc--;
|
||||
return *this;
|
||||
}
|
||||
Licznik operator--(int) {
|
||||
Licznik stary = *this;
|
||||
--wartosc;
|
||||
return stary;
|
||||
}
|
||||
Licznik &operator=(const Licznik &inny_licznik) {
|
||||
if (this != &inny_licznik) {
|
||||
wartosc = inny_licznik.wartosc;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
friend std::ostream &operator<<(std::ostream &os, Licznik &licznik) {
|
||||
os << licznik.wartosc;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
// int main() {
|
||||
// Licznik a(5);
|
||||
// std::cout << a++ << std::endl; // 6
|
||||
// std::cout << a << std::endl; // 6
|
||||
// std::cout << ++a << std::endl; // 7
|
||||
// }
|
||||
Reference in New Issue
Block a user