fork download
  1.  
  2.  
  3. class OperatorTest {
  4. public:
  5. OperatorTest() = default;
  6.  
  7. OperatorTest(int a) : a(a) {}
  8.  
  9. int a = 0;
  10. };
  11.  
  12. class OperatorInside : public OperatorTest {
  13. public:
  14. using OperatorTest::OperatorTest;
  15.  
  16. OperatorInside operator+(const OperatorInside &rhs) {
  17. const OperatorInside sum(a + rhs.a);
  18. return sum;
  19. }
  20. };
  21.  
  22. class OperatorOutside : public OperatorTest {
  23. public:
  24. using OperatorTest::OperatorTest;
  25. };
  26.  
  27. OperatorOutside operator+(const OperatorOutside &lhs,
  28. const OperatorOutside &rhs) {
  29.  
  30. const OperatorOutside sum(lhs.a + rhs.a);
  31. return sum;
  32. }
  33.  
  34. int main() {
  35. OperatorInside ai(1);
  36. OperatorInside bi(2);
  37.  
  38. OperatorInside si = ai + bi;
  39.  
  40. OperatorOutside ao(1);
  41. OperatorOutside bo(2);
  42.  
  43. OperatorOutside so = ao + bo;
  44. }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
Standard output is empty