gpt4 book ai didi

c++ - Visual Studio 2008 -> 2010 端口 : error C2039: 'select2nd' : is not a member of 'std'

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

我正在将一个大型 C++ COM 项目从 VS2008 移植到 VS2010。有一行代码如下,在我的VS2008项目中编译正常,但在VS2010中编译时给出引用错误:

std::select2nd<std::map<DWORD, ISomethingUseful*>::value_type>());

编译错误为:

error C2039: 'select2nd' : is not a member of 'std'

我知道这是一个“非标准”函数,但是编写这段代码的人最初在 VS2008 中的 std 命名空间中找到了它,无论他们使用哪个 #include 似乎在 VS2010 中都不再正确。

有谁知道这个函数现在在 VS2010 中的什么位置?以及现在需要包含哪个头文件才能使用它?


编辑:为了暂时解决这个问题,我从 VS2008 VC\include\functional 头文件中获取了代码,并将其包含在我的代码库中(在实用程序类中),如下面的回答所述。

仍然会感谢任何其他人能够提供的任何见解!

最佳答案

好吧,看来这个问题的答案是 std::select2nd(...) 函数在 VS2008 中通过 functional 库得到了支持,但是它已在 VS2010 中弃用。下面是来自 VS2008 的代码,如果需要,可以在将代码移植到 VS2010 时重新体现此功能:

template<class Pair> struct select2nd : public std::unary_function<Pair, typename Pair::second_type>
{
// functor for unary second of pair selector operator
const typename Pair::second_type& operator()(const Pair& Left) const
{
// apply second selector operator to pair operand
return (Left.second);
}
};

关于c++ - Visual Studio 2008 -> 2010 端口 : error C2039: 'select2nd' : is not a member of 'std' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11517146/

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