fork download
  1. #include <iostream>
  2.  
  3. class PublicClass
  4. {
  5. friend class PublicClassImpl;
  6. int idx;
  7. public:
  8. PublicClass() : idx (42) {}
  9. void DoWork();
  10. };
  11.  
  12. // In the implementation file:
  13. class PublicClassImpl
  14. {
  15. public:
  16. static void DoWorkImpl(PublicClass& target);
  17. };
  18.  
  19. void PublicClass::DoWork()
  20. {
  21. PublicClassImpl::DoWorkImpl(*this);
  22. }
  23.  
  24. void PublicClassImpl::DoWorkImpl(PublicClass& target)
  25. {
  26. std::cout << "Index is currently " << target.idx++ << std::endl;
  27. }
  28.  
  29. int main() {
  30. PublicClass pc;
  31. pc.DoWork();
  32. pc.DoWork();
  33. return 0;
  34. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Index is currently 42
Index is currently 43