gpt4 book ai didi

c++ - std::forward 编译错误 VS2010

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:19 25 4
gpt4 key购买 nike

我从文件 utility(它位于 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\),它正在我的项目中使用 Visual C++ 10.0 进行编译。

'std::forward' : cannot convert parameter 1 from '' to '&'

template<class _Other1, class _Other2>
pair(_Other1&& _Val1, _Other2&& _Val2)
: _Mybase(_STD forward<_Other1>(_Val1), _STD forward<_Other2>(_Val2))
{ // construct from moved values
}

谁能解释这个错误?在我看来这很奇怪,但我是 C++ 的新手,我不知道如何修复它。


错误似乎在这里:

std::map<std::string, DWORD>::value_type("SOME_STRING", 8192);

编译报告如下:

see reference to function template instantiation 
'std::pair<_Ty1,_Ty2>::pair<const char(&)[12],>(_Other1,_Other2 &&)'
being compiled with
[
_Ty1=const std::string,
_Ty2=DWORD,
_Other1=const char (&)[12],
_Other2=
]

最佳答案

编译器似乎无法处理传入的字符串文字。我不知道它是否是 VS2010 使用的标准库实现中的错误,或者它是否遇到了标准中的边缘情况(实际上应该是失败),但无论哪种方式,您都可以通过根据文字显式创建 std::string 来解决它:

std::map<std::string, DWORD>::value_type(std::string("SOME_STRING"), 8192);

关于c++ - std::forward 编译错误 VS2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20884137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com