I think you're looking for a "runtime" solution, not a compile-time one... I'm thinking more down the path of:
Code:
Code:
#include <iostream>
#include <string>
class Resource
{
};
class TileSet : public Resource
{
};
class Provider
{
public:
virtual Resource* Create() = 0;
};
class TileSetProvider : public Provider
{
public:
virtual Resource* Create() { return new TileSet(); }
};
class ResourceManager
{
public:
void AddProvider(Provider* p) { this->provider = p; }
template<typename B>
B* GetAsset(std::string& name) { return dynamic_cast<B*>(this->provider->Create()); }
Provider* provider;
};
int main()
{
ResourceManager resourceManager;
resourceManager.AddProvider(new TileSetProvider());
TileSet* ts = resourceManager.GetAsset<TileSet>("grass");
}
Though then again, more information on the application would be helpful... (as the provided example is not complete).