问题描述
我有一些代码,其中计算结果取决于var jsonResponse = JsonConvert.DeserializeObject<NumberResultModel>(Jason);
变量。我可以通过许多不同的方式使用此变量,但是其中一个特定的变量无法编译,我也不明白为什么。我试图将问题隔离并尽可能减少到最小。考虑以下示例(Compiler Explorer link):
private constexpr
在函数`Test :: Bar(int)const'中:
/ home / ce /:23:对`Test :: foo'的未定义引用
编译器返回:1
我不明白为什么会发生这种情况,特别是因为当我不使用#include <algorithm>
class Test
{
public:
void Do();
int result;
private:
int Bar(const int bar) const;
static constexpr auto foo = 10;
};
void Test::Do()
{
result = Bar(123);
}
int Test::Bar(const int bar) const
{
const auto y = std::max(foo,bar);
return y;
}
int main(const int argc,const char * const argv[])
{
Test t;
t.Do();
return t.result;
}
时,即当我用std::max
替换第23行时,这种情况消失了。
我正在使用g ++ 7.5.0,但是我在Compiler Explorer上尝试了所有可用的较新版本。我也尝试了clang,但是链接器错误仍然存在。关于 const auto y = foo > bar ? foo : bar;
与std::max
变量的结合在原理上是否起作用?我不知道有什么限制,这对我来说似乎很奇怪。我很乐意对此行为做出解释。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)