【发布时间】:2018-09-27 14:42:28
【问题描述】:
我创建了一个读取 JSON 的函数来在 OpenCV 中设置我的屏幕,但是当它返回一个字符串时,它给出了以下错误:
In member function ‘std::__cxx11::string JsonControl::GetJson(std::__cxx11::string)’: /home/developer/Documents/Develloper/Kamino_Project/kamino_vizualization/modules/drivenet/src/json/read_json.cpp:27:1: error: control reaches end of non-void function [-Werror=return-type] }
string JsonControl::GetJson(string getData)
{
read_json("../modules/src/json/resources.json", root);
BOOST_FOREACH (boost::property_tree::ptree::value_type &v, root.get_child(getData))
{
std::cout << v.second.data() << std::endl;
stringstream geek(v.second.data());
geek >> returnValue;
return returnValue;
}
}
string JsonControl::SetDataJson(string setData){
returnValue = GetJson(setData);
return returnValue;
}
非常感谢……
【问题讨论】:
-
如果循环执行 0 次会发生什么?你返回什么?
-
将
return returnValue;移出BOOST_FOREACH块,希望你已经在别处声明并初始化了returnValue。 -
谢谢,你们两个是对的。这是工作。我学会了
标签: c++ string function compiler-errors return-value