Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Liczba {
  5. public:
  6. Liczba(int n) : liczba(n) {} // -pokazuje co zrobić gdy program napotka int
  7. // w miejscu gdzie oczekiwał Liczbę
  8. Liczba(const Liczba& l){liczba=l.liczba;
  9. cout<<"dziala konstruktor kopiujacy";}
  10. Liczba operator +(Liczba& l){liczba=liczba+l.liczba;
  11. cout<<"dziala operator +";}
  12. operator int() const { // -pokazuje co zrobić gdy program
  13. // napotka Liczbę tam gdzie oczekiwał int
  14. cout<<"dziala operator int";
  15. return liczba;
  16. }
  17. int liczba;
  18. };
  19. int main() {
  20. Liczba Lobj1(5);
  21. Liczba Lobj2 = Lobj1 + 5; // teraz element liczba obiektu Lobj2 ma wartość 10
  22. system("pause");}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement