[ create a new paste ] login | about

Link: http://codepad.org/hURgwat6    [ raw code | output | fork ]

C++, pasted on Nov 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

class C {
private:
  int n;
public:
  C() : n(0) {}
  C(int n) : n(n) {}
  friend C operator+(C &a, C &b) { C c; c.n = a.n + b.n; return c; }
  friend C operator+(C &a, int n) { C c; c.n = a.n + n; return c; }
  friend std::ostream &operator<<(std::ostream &s, C c) { return s << c.n; }
};

int main() {
  C a(1), b(2);
  std::cout << a + b << std::endl;
  std::cout << a + 5 << std::endl;
  return 0;
}


Output:
1
2
3
6


Create a new paste based on this one


Comments: