Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- class A {
- private:
- int x;
- public:
- A(int _x) {
- x = _x;
- }
- A& operator=(int t) {
- x = t;
- return *this;
- }
- A& operator=(A t) {
- x = t.x;
- return *this;
- }
- A& operator+=(int t) {
- x += t;
- return *this;
- }
- A& operator+=(A t) {
- x += t.x;
- return *this;
- }
- void print();
- };
- void A::print() { // Использование ::
- cout << x << "\n";
- }
- int main() {
- // Перегрузка операторов
- A x(4), y(3);
- y = 7;
- x.print();
- y.print();
- x += y;
- y += 1;
- x.print();
- y.print();
- // list
- list<int> lst;
- lst.push_back(1);
- lst.push_back(2);
- lst.push_back(3);
- cout << lst.size() << "\n";
- cout << *lst.begin() << "\n";
- *lst.begin() *= 10;
- cout << *lst.begin() << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement