Given the following:

```
class Curve {
public:
  typedef boost::shared_ptr<Curve> Pointer;
  // ...
private:
  // ...
};

class CurveShift: public Curve {
public:
  CurveShift(const Curve & curve);
  // ...
private:
  const Curve & curve_;
  // ...
};

```

I was wondering whether there is a consensus best practice to use when you want to do something like:

```
Curve::Pointer pointer(new Curve());
SomeGlobalRepository::Add("key", pointer);

```

And in some other place you have:

```
CurveShift cs(*SomeGlobalRepository::Get("key"));

```

You don't really have any assurance that `SomeGlobalRepository` will contain the original `Curve::Pointer` when `CurveShift` will need it, and hence `curve_` might point to deallocated memory, or even memory that was already reallocated to something else. I believe that one possible solution would be for `CurveShift` to use a `boost:weak_ptr<Curve>` instead of a `const Curve &`, but I am pretty certain that would mean that you can't use `Curve` on the stack anymore, and any instance would have to go on the heap (with the constructors becoming private and the objects being created through a factory). Is there a better strategy to achieve the desired behavior? My gut feeling is that while in theory this could be a serious problem, practical use cases would not lend themselves to creating these tricky situations.