fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class Obiekt
  7. {
  8. public:
  9. const int liczba;
  10.  
  11. Obiekt();
  12. Obiekt &operator=(const Obiekt &wzor);
  13. };
  14.  
  15. Obiekt::Obiekt() : liczba(10)
  16. {
  17. }
  18.  
  19. Obiekt &Obiekt::operator=(const Obiekt &wzor)
  20. {
  21. if(this != &wzor)
  22. {
  23. liczba = wzor.liczba;
  24. }
  25. return *this;
  26. }
  27.  
  28. int main()
  29. {
  30. Obiekt test1;
  31. Obiekt test2;
  32. test2 = test1;
  33. cout << test2.liczba;
  34.  
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘Obiekt& Obiekt::operator=(const Obiekt&)’:
prog.cpp:23:10: error: assignment of read-only member ‘Obiekt::liczba’
   liczba = wzor.liczba;
          ^
stdout
Standard output is empty