fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //GraphDevice.h
  5. struct Application;
  6. struct GraphDevice
  7. {
  8. friend struct Application;
  9. struct Impl;
  10. GraphDevice();
  11. private:
  12. void initialize();
  13. Impl *impl;
  14. };
  15. //GraphDevice.cpp
  16.  
  17. struct GraphDevice::Impl
  18. {
  19. void initialize()
  20. {
  21. cout << "initialize!" << endl;
  22. }
  23. };
  24.  
  25. GraphDevice::GraphDevice()
  26. {
  27. impl = new Impl;
  28. }
  29.  
  30. void GraphDevice::initialize()
  31. {
  32. impl->initialize();
  33. }
  34.  
  35. //Application.h
  36. struct Application
  37. {
  38. struct Impl;
  39. Application();
  40. void initialize();
  41. private:
  42. Impl *impl;
  43. };
  44.  
  45. //Application.cpp
  46. struct Application::Impl
  47. {
  48. GraphDevice *gd;
  49. void initialize()
  50. {
  51. gd = new GraphDevice;
  52. gd->initialize();
  53. }
  54. };
  55.  
  56. Application::Application()
  57. {
  58. impl = new Impl;
  59. }
  60.  
  61. void Application::initialize()
  62. {
  63. impl->initialize();
  64. }
  65.  
  66. //main.cpp
  67. int main() {
  68. Application app;
  69. app.initialize();
  70. return 0;
  71. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
initialize!