Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Liczba {
- public:
- Liczba(int n) : liczba(n) {} // -pokazuje co zrobić gdy program napotka int
- // w miejscu gdzie oczekiwał Liczbę
- Liczba(const Liczba& l){liczba=l.liczba;
- cout<<"dziala konstruktor kopiujacy";}
- Liczba operator +(Liczba& l){liczba=liczba+l.liczba;
- cout<<"dziala operator +";}
- operator int() const { // -pokazuje co zrobić gdy program
- // napotka Liczbę tam gdzie oczekiwał int
- cout<<"dziala operator int";
- return liczba;
- }
- int liczba;
- };
- int main() {
- Liczba Lobj1(5);
- Liczba Lobj2 = Lobj1 + 5; // teraz element liczba obiektu Lobj2 ma wartość 10
- system("pause");}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement