fork(2) download
  1. class Base {
  2. public:
  3.  
  4. class Thing {
  5. public:
  6. Thing(Base& b) : _b(b) {};
  7.  
  8. Thing& operator+= (const Thing p) { _b.add(*this, p); return *this; };
  9.  
  10. int k;
  11. protected:
  12. Base& _b;
  13. };
  14.  
  15. void add(Thing &d, const Thing s) { d.k += s.k; }
  16. };
  17.  
  18. template <class... Interfaces>
  19. class Extensible : virtual public Base, virtual public Interfaces... {
  20.  
  21. class Thing : virtual public Base::Thing, virtual public Interfaces::Thing... {
  22.  
  23. };
  24. };
  25.  
  26. class SomeInterface : Base {
  27. void multiply(Thing &d, const Thing s) { d.k *= s.k; }
  28.  
  29. class Thing : public Base::Thing {
  30. Thing& operator*= (const Thing p) {
  31. //_b.multiply(*this, p); return *this; // <-- won't work of course
  32. };
  33.  
  34. };
  35.  
  36. };
  37.  
  38. int main() {
  39. Extensible<SomeInterface> a;
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty