我有一个函数,但我无法更改其函数参数。我需要返回一个指向此函数中创建的std::string的常量引用。我尝试使用boost shared_ptr,但这不起作用。为什么?我该怎么做才能让它起作用?
const std::string& getVal(const std::string &key) {
boost::shared_ptr<std::string> retVal(new std::string());
... //build retVal string with += operator based on key
return *retVal;
}