无法确定正确的返回类型
failed to determine the correct return type
我有以下简化的文件和类:
统计:
class Stat
{
auto getMinMaxValue(std::unordered_map< int, int >&);
};
统计.cpp:
auto Stat::getMinMaxValue(std::unordered_map< int, int >&m)
{
return std::minmax_element(m.begin(), m.end(), [](const pair<int, int>& p1, const pair<int, int>& p2) { return p1.second < p2.second; });
}
StatCount.h:
class StatCount : public Stat
{
void setWeight(std::vector<D> const&, const std::string);
};
统计计数.cpp:
void StatCount::setWeight(vector<D> const& ref, const string type)
{
auto a = Stat::getMinMaxValue(m_value);
cout << "MIN: " << a.first->second << endl;
cout << "MAX: " << a.second->second << endl;
}
由于如果我使用自动返回类型,我将函数"getMinMaxValue"声明到基类 Stat 中,因此出现错误:
function 'getMinMaxValue' with deduced return type cannot be used before it is defined
但我未能删除自动返回类型并找到正确的语法来指定方法"getMinMaxValue"的返回类型
如果我阅读有关 CPP首选项的文档,我看到它一定是一对迭代器,但是如何?
我回应自己,似乎我已经找到了解决方案:
统计:
std::pair<std::unordered_map< int, int >::iterator, std::unordered_map< int, int >::iterator> getMinMaxValue(std::unordered_map< int, int >&);
相关文章:
- c++ 11 带有 decltype 的尾随返回类型无法按预期工作
- 如何确定模板的返回类型?
- 用户定义的转换无法指定返回类型
- 无法推断返回类型的模板参数
- 必须使用尾随返回类型的示例,因为无法用旧方法解决问题
- 如何确定三元运算符的返回类型?
- C++:返回类型为 T 的模板函数不带 T 类型参数,将无法编译
- 确定功能主体中的返回类型
- 无法识别协变返回类型
- 编译器无法推断返回类型?
- std::d eclval vs crtp,无法从不完整类型推断方法返回类型
- 无法为unique_ptr返回类型返回 nullptr
- 自动无法推断出正确的返回类型
- 为什么编译器无法推断返回类型?
- 确定模板函数的返回类型
- 无法确定正确的返回类型
- 无法使用 std::map 推断 lambda 的返回类型
- Clang无法在模板类专业化中编译模板功能,该模板类专业化与模板声明具有 *不同的返回类型 *
- 不确定的函数返回类型
- 当我使用模板时,编译器无法将函数的返回类型从 double 转换为 int