这大概是一个视觉工作室2017 /questions/tagged/visual-studio-2017与此问题相关的错误:Visual Studio 中 Lambda 的模板变量错误? https://stackoverflow.com/q/49117293/2642059 And as 评论中提到 https://stackoverflow.com/questions/49117293/templated-variables-bug-with-lambdas-in-visual-studio#comment85240480_49117293似乎与优化器有关。
a 的定义中的除法变量模板 http://en.cppreference.com/w/cpp/language/variable_templateVisual Studio 2017 中似乎有一个错误。例如以下代码:
template <typename T>
const T PI = std::acos(static_cast<T>(-1));
template <typename T>
const T ONE_EIGHTY = 180;
template <typename T>
const T DEG_TO_RAD = PI<T> / ONE_EIGHTY<T>;
int main() {
cout << DEG_TO_RAD<float> << endl;
}
在海湾合作委员会 6.3 https://ideone.com/IbCGA0这输出:
0.0174533
在 Visual Studio 2017 上,输出:
0.0
我假设这是另一个 Visual Studio 错误?这里有解决方法吗?
应@JonathanMee 的要求在此处发布解决方法,因为它也works https://stackoverflow.com/a/49119415/8746007对于他之前报告的类似问题。似乎与最新 VS2017 中的某种错误有关,该错误阻止模板自动激活并需要强制激活:
template <typename T>
const T PI = std::acos(static_cast<T>(-1));
template <typename T>
const T ONE_EIGHTY = 180;
template <typename T>
const T DEG_TO_RAD = PI<T> / ONE_EIGHTY<T>;
int main()
{
PI<float>; // <---- workaround
std::cout << DEG_TO_RAD<float> << std::endl;
}
以下是向 Microsoft 提交的错误通知单:https://developercommunity.visualstudio.com/content/problem/207741/template-needs-to-be-force-instantiated-vs2017-bug.html https://developercommunity.visualstudio.com/content/problem/207741/template-needs-to-be-force-instantiated-vs2017-bug.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)