I have the following class
class CItem
{
public:
CItem(CRegistry &Registry) _Registry(Registry) {Registry.Register();}
~CItem() {_Registry.Unregister()};
private:
CRegistry &_Registry;
}
After a while it turns out that not all CItem objects need to be registered so I need a version of CItem which does not requires Registry in constructor (and of course of the registration code). How can I implement this? The only solution I can see here is to get and keep Registry as a pointer. Is there more elegant solution, like using templates, etc (I don't like switching from reference to pointer)?