fork download
  1.  
  2. struct Interface
  3. {
  4. virtual void foo() = 0;
  5. virtual ~Interface() {}
  6. };
  7.  
  8. class Implementation
  9. {
  10. struct InterfaceImpl : Interface
  11. {
  12. InterfaceImpl(Implementation* impl)
  13. : impl_(impl) {}
  14. virtual void foo() { impl_->doFoo(); }
  15.  
  16. Implementation* impl_;
  17. };
  18.  
  19. public:
  20. Implementation()
  21. : interfaceImpl_(this) {}
  22.  
  23. Interface* getInterface() { return &interfaceImpl_; }
  24.  
  25. private:
  26. InterfaceImpl interfaceImpl_;
  27.  
  28. void doFoo() {}
  29. };
  30.  
  31. int main() {
  32. Implementation impl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty