Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // a.hpp
- #pragma once
- #include <memory>
- #include "b.hpp"
- class A {
- private:
- std::unique_ptr<B> b;
- public:
- A();
- void dernut_b() const;
- void dernut() const;
- };
- // a.cpp
- #include "a.hpp"
- #include <iostream>
- A::A() : b { std::make_unique<B>(*this) } {}
- void A::dernut_b() const {
- b->dernut();
- }
- void A::dernut() const {
- std::cout << "A - dernuli" << std::endl;
- }
- // b.hpp
- #pragma once
- class A;
- class B {
- private:
- A& owner;
- public:
- B(A& owner);
- void dernut() const;
- };
- // b.cpp
- #include "b.hpp"
- #include <iostream>
- #include "a.hpp"
- B::B(A& owner) : owner { owner } {}
- void B::dernut() const {
- std::cout << "dernuli B" << std::endl;
- owner.dernut();
- }
- // program.cpp
- #include "a.hpp"
- int main() {
- A a;
- a.dernut_b();
- }
Advertisement
Add Comment
Please, Sign In to add comment