I have the following situation: there is class of GraphicsContext:
class GraphicsContext {
...
private:
std::unique_ptr<Renderer> m_renderer;
}
And there is a class of application that uses the GraphicsContext:
class Application {
...
private:
std::unique_ptr<GraphicsContext> m_graphicsContext;
}
And there are sub-level classes those are used in Application class and those uses Renderer from the GraphicsContext. I need to store pointer to the renderer in these classes, but how should I do that?
class SubLevelClass {
public:
SubLevelClass(Renderer* renderer);
...
void drawSomething();
private:
Renderer* m_renderer; // this class is not owner of Renderer but should can ability to refer to it
}
Such sub-level classes does not semantically own the Renderer and therefore I think it't not good idea to use shared_ptr instead of unique_ptr. But how to organize such ownership if it's garanteed that objects of sub-level classes live lesser time than Application object? Can I store and return from GraphicsContext a raw pointer to Renderer or it's semantically wrong idea?