Guest User

Untitled

a guest
Oct 21st, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. // a.hpp
  2. #pragma once
  3.  
  4. #include <memory>
  5.  
  6. #include "b.hpp"
  7.  
  8. class A {
  9. private:
  10.     std::unique_ptr<B> b;
  11. public:
  12.     A();
  13.     void dernut_b() const;
  14.     void dernut() const;
  15. };
  16.  
  17.  
  18. // a.cpp
  19. #include "a.hpp"
  20.  
  21. #include <iostream>
  22.  
  23. A::A() : b { std::make_unique<B>(*this) } {}
  24.  
  25. void A::dernut_b() const {
  26.     b->dernut();
  27. }
  28.  
  29. void A::dernut() const {
  30.     std::cout << "A - dernuli" << std::endl;
  31. }
  32.  
  33. // b.hpp
  34. #pragma once
  35.  
  36. class A;
  37.  
  38. class B {
  39. private:
  40.     A& owner;
  41. public:
  42.     B(A& owner);
  43.     void dernut() const;
  44. };
  45.  
  46. // b.cpp
  47. #include "b.hpp"
  48.  
  49. #include <iostream>
  50.  
  51. #include "a.hpp"
  52.  
  53. B::B(A& owner) : owner { owner } {}
  54.  
  55. void B::dernut() const {
  56.     std::cout << "dernuli B" << std::endl;
  57.     owner.dernut();
  58. }
  59.  
  60.  
  61. // program.cpp
  62. #include "a.hpp"
  63.  
  64. int main() {
  65.     A a;
  66.     a.dernut_b();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment