【发布时间】:2012-01-03 10:30:37
【问题描述】:
我想为我的游戏做一些存储。现在代码看起来像:
class WorldSettings
{
private:
std::map<std::string, int> mIntegerStorage;
std::map<std::string, float> mFloatStorage;
std::map<std::string, std::string> mStringStorage;
public:
template <typename T>
T Get(const std::string &key) const
{
// [?]
}
};
所以,我有一些关联容器来存储确切类型的数据。现在我想在设置中添加一些值:settings.Push<int>("WorldSize", 1000); 并得到它:settings.Get<int>("WorldSize");。但是由于传递的类型到模板中,如何切换需求映射?
或者,也许,您知道更好的方法,谢谢。
【问题讨论】: