This is a bit far-fetched, but I will say that I have such a class interface:
class IResource;
class IResourceContainer
{
public:
virtual ~IResourceContainer() {}
virtual void AddResource(const std::string& rStrName,
std::auto_ptr<IResource> apResource)=0;
virtual IResource& GetResource(const std::string& rStrName)=0;
};
and I have an implementation of this class that contains a string map for IResource types. If I added my own resource as follows:
container.AddResource("foo", std:auto_ptr<IResource>( new CFooResource);
and then get a link to the resource
CFooResource& fooResource = container.GetResource();
This will not compile since I will need to knock down IResource on CFooResource. I thought about hiding this by forcing GetResource to accept a template parameter that omits the type inside, but obviously templates and clean interfaces do not jive. My alternative is to hide the casting in the CastResource function, which calls boost :: polymorphic_downcast, but I'm still not happy with the idea that the client will need to use the resource.
For instance:
CFooResource& fooResource = CastResource<CFooResource&>(container.GetResource());
, , : , ? , , . , , , .
.