简体   繁体   English

'mem_fun':不是'std'的成员

[英]'mem_fun' : is not a member of 'std'

I've been experiencing this error for a while now, on every project that I have built with the CryEngine2 SDK in Visual Studio 2013 Professional. 在Visual Studio 2013 Professional中使用CryEngine2 SDK生成的每个项目上,我都遇到了一段时间的错误。 Most of the time, I have just edited the function from this: 大多数时候,我只是从这里编辑函数:

void CMultipleGrabHandler::Reset()
{
    std::for_each (m_handlers.begin(), m_handlers.end(), std::mem_fun (&CBaseGrabHandler::Reset));

    std::vector <CAnimatedGrabHandler*>::iterator it = m_handlers.begin();
    std::vector <CAnimatedGrabHandler*>::iterator end = m_handlers.end();
    for ( ; it != end; ++it)
        delete *it;

    m_handlers.erase (m_handlers.begin (), m_handlers.end ());
}

to this: 对此:

void CMultipleGrabHandler::Reset()
{
}

I know it's not a good approach to the problem, but it got rid of the 'mem_fun' : is not a member of 'std' error. 我知道这不是解决问题的好方法,但是它摆脱了'mem_fun' : is not a member of 'std'错误'mem_fun' : is not a member of 'std'

I am now looking for a solution to overcome this problem, since I have just started working on a new project, where stability is key; 我现在正在寻找解决该问题的解决方案,因为我刚刚开始从事一个新项目,而稳定性是关键。 it's not good if I remove the body of CMultipleGrabHandler::Reset() , since it could possibly induce crashes in certain situations. 如果删除CMultipleGrabHandler::Reset()的主体,那是不好的 ,因为在某些情况下可能会导致崩溃。 I have browsed the internet for a solution to this problem, but I have not found anything (closest thing I found was an explanation of what mem_fun does). 我已经浏览了互联网以找到解决该问题的方法,但是我什么也没找到(我发现的最接近的东西是对mem_fun的解释)。

I have tried taking std:: off mem_fun , but I just get an mem_fun is undefined error, suggesting that this isn't exactly the right way to go about mending this error. 我尝试过将std:: off mem_fun ,但是我刚得到一个mem_fun is undefined错误,表明这不是修复此错误的正确方法。

The project was originally created in Visual Studio 2005, and was migrated to Visual Studio 2013's format when I first opened the solution. 该项目最初是在Visual Studio 2005中创建的,当我第一次打开该解决方案时,已迁移为Visual Studio 2013的格式。 Might this be the cause of the problem? 这可能是问题的原因吗? How can it be fixed? 如何解决?

Edit: Added as this also applies to the new VS version. 编辑:添加了因为这也适用于新的VS版本。

The function std::mem_fun is defined in the header <functional> . 函数std::mem_fun在头文件<functional>定义。

On some older compilers, you don't necessarily need to #include a standard library header in order to use functions and classes defined in that header, because it might already be included by some other standard library header that you #include . 在某些较旧的编译器上,不必使用#include标准库头文件即可使用该头文件中定义的函数和类,因为#include可能已将其包含在其他一些标准库头文件中。 This is not exclusive to VS; 这不是VS独有的。 it was also true for older gcc versions, like 4.0. 对于较旧的gcc版本(例如4.0)也是如此。 Newer compilers are more standard-conforming and will require you to #include the actual headers that define standard library functions and classes. 较新的编译器更符合标准,将要求您#include定义标准库函数和类的实际标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM