【发布时间】:2015-01-17 18:43:38
【问题描述】:
我正在使用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&
将不胜感激任何帮助或解释。
谢谢!
【问题讨论】:
-
如果按值返回结果,则不能将其作为非常量引用参数。
-
无关:你为什么使用
new? -
0x499602d2:因为我需要在一个向量中管理所有这些新对象,并且该向量的类型是一个抽象类,它首先来自...抽象对象...