所以,這裏是我的類及其功能:的boost :: shared_ptr的和nullptr預設模板函數參數
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;
}
}
}
這個類是靜態庫,它compliles沒有問題。然而,當我使用它在正常的應用程序:
cResourceManager<sf::Texture> resourceManager;
resourceManager.add("1.PNG");
我得到錯誤: 錯誤:類型的參數默認參數 '的boost :: shared_ptr的' 有型 '的std :: nullptr_t'
我不知道這裏有什麼問題,不能shared_ptr有nullptr值? 我使用g ++ 4.7和-std = C++ 11
謝謝!
shared_ptr現在在C++ 11標準中了嗎?第二個問題,做boost :: shared_ptr有一些nullptr關鍵字? – user1873947