0
我想實現一個字符串。我想將字符串轉換爲小寫,所以叫做boost::to_lower_copy(m_s)
。實際上,m_s
的類型是std::string
。我的問題是return {boost::to_lower_copy(m_s)};
如何在函數to_lower_copy()
中工作。它怎麼會返回一個String類型? 非常感謝。「return {...};」如何在C++ 11中工作?
class String {
std::string m_s;
public:
String(const std::string s) : m_s(s) { }
String to_lower_copy() const {
return {boost::to_lower_copy(m_s)};
}
};
'return {...}'調用'std :: string {...}',並返回新構造的字符串。它這樣做是因爲編譯器知道函數需要返回一個std :: string。 –
@RichardCritten,爲什麼在評論中回答?您應該將您的評論轉換爲答案。 –
@RichardCritten你是不是指'String'? – LogicStuff