【发布时间】:2012-12-09 11:48:53
【问题描述】:
所以,这是我的课程及其功能:
template <class T>
class cResourceManager
{
public:
bool add(const std::string & key, boost::shared_ptr<T> ptr = nullptr);
private:
std::map <const std::string, boost::shared_ptr<T> > resources;
};
template <class T>
bool cResourceManager<T>::add(const std::string & key, boost::shared_ptr<T> ptr)
{
if (resources.find(key) == resources.end())
{
if(ptr != nullptr) //we have the object
{
resources.insert(std::pair<const std::string, boost::shared_ptr<T>>(key, ptr));
return true;
}
else //we need to load object using sfml loadFromFile
{
T tempResource;
tempResource.loadFromFile(key);
resources.insert(std::pair<const std::string, boost::shared_ptr<T>>(key, new T(tempResource)));
if(resources[key] == nullptr) return false;
else return true;
}
}
}
该类在静态库中,它编译没有问题。但是,当我在正常应用中使用它时:
cResourceManager<sf::Texture> resourceManager;
resourceManager.add("1.PNG");
我得到错误: 错误:“boost::shared_ptr”类型参数的默认参数类型为“std::nullptr_t”
我不知道这里出了什么问题,shared_ptr 不能有 nullptr 值吗? 我使用 g++ 4.7 和 -std=c++11
谢谢!
【问题讨论】:
标签: c++ boost c++11 shared-ptr