fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Integer
  5. {
  6. private:
  7. int value;
  8. public:
  9. Integer(int i): value(i)
  10. {}
  11. const Integer operator+(const Integer& rv) const {
  12. return (value + rv.value);
  13. }
  14.  
  15. void constMethod() const {
  16. cout << "const\n";
  17. }
  18.  
  19. void nonConstMethod() {
  20. cout << "non-const\n";
  21. }
  22.  
  23. };
  24.  
  25. int main() {
  26.  
  27. Integer a{1};
  28. Integer b{2};
  29.  
  30. (a + b).constMethod();
  31. //(a + b).nonConstMethod();
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
const