Code/Recipes/Smart pointer

From Polytech Center Barcelona
Jump to: navigation, search
#include <memory>

struct god
{
};

using god_ptr = std::shared_ptr<god>;

struct earth
{
    earth(god_ptr g);
    god_ptr g_;
};

struct sun
{
    sun(god_ptr g);
    god_ptr g_;
};

earth::earth(god_ptr g)
  : g_(g)
{
}

sun::sun(god_ptr g)
  : g_(g)
{
}

int main()
{
    auto g = std::make_shared<god>();
    earth e(g);
    sun s(g);
    return 0;
}