我正在使用boost::property_tree::ptree
并parse_ini
读取一个ini文件。使用ptree::iterator
我正在获取 ini 部分并希望使用它们来创建另一个对象。
我有一个叫做First
得到的对象First(int& i, string& str)
所以我正在尝试使用从 ptree 函数获得的返回值来构建新对象,例如(posision
是我的ptree::iterator
)
First* one = new First(
boost::lexical_cast<int>((posision->second).get<int>("number")),
(posision->second).get<string>("name")
);
但我明白了
no matching function for call to ‘First::First(int, std::basic_string<char>)’
所以我尝试像这样铸造:
First* one = new First(
(int&) boost::lexical_cast<int>((posision->second).get<int>("number")),
(string&) (posision->second).get<string>("name")
);
但后来我得到了
invalid cast of an rvalue expression of type ‘int’ to type ‘int&’
和
invalid cast of an rvalue expression of type ‘std::basic_string<char>’ to type ‘std::string&
将不胜感激任何帮助或解释。
谢谢 !