All submissions

Method Chaining with this

#include <iostream>
using namespace std;

class Counter {
private:
   int value;
public:
   Counter() : value(0) {}
   // your code here: implement increment() to add 1 and return *this
   // your code here: implement decrement() to subtract 1 and return *this
   int getValue() const {
       return value;
   }

inline Counter& increment() { value++; return *this; }
inline Counter& decrement() { value--; return *this; }

};

int main() {
   Counter c;
   // example chain of calls
   c.increment().increment().decrement();
   cout << c.getValue();
   return 0;
}
Loading...

Input

Expected Output

1