'mem_fun':不是'std'的成员 [英] 'mem_fun' : is not a member of 'std'

查看:390
本文介绍了'mem_fun':不是'std'的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2013 Professional中使用CryEngine2 SDK建立的每个项目都遇到了这个错误。
大多数时候,我刚刚编辑了这个函数:

  void CMultipleGrabHandler :: Reset b $ b {
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());
}

  void CMultipleGrabHandler :: Reset()
{
}

我知道这不是一个好的方法,但它摆脱了'mem_fun':不是'std'错误的成员。



我现在正在寻找一个解决方案来克服这个问题,因为我刚刚开始一个新的项目,其中稳定性是关键;如果我删除 CMultipleGrabHandler :: Reset()的正文,因为它在某些情况下可能会导致崩溃,因此它不是好的。
我已经浏览互联网解决这个问题,但我没有找到任何东西(最接近的事情,我发现是 mem_fun 的解释。)。 / p>

我尝试过 std :: 关闭 mem_fun 但我只是得到一个 mem_fun是未定义的错误,表明这不是正确的方法去修复此错误。



项目最初是在Visual Studio 2005中创建的,并且在我第一次打开解决方案时迁移到Visual Studio 2013的格式。
这可能是问题的原因吗?
如何修正?



编辑 已添加 visual-studio-2015 ,因为这也适用于新的VS版本。

解决方案

定义函数 std :: mem_fun < functional>



在一些较旧的编译器上,您不一定需要 #include 一个标准库头,以便使用在该头中定义的函数和类,因为它可能已经被其他标准库头包括# include 。这不是VS独有的;它也是真的对于旧的gcc版本,如4.0。较新的编译器更符合标准,并且需要您定义标准库函数和类的实际头文件 #include


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. 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.

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. 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).

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.

The project was originally created in Visual Studio 2005, and was migrated to Visual Studio 2013's format when I first opened the solution. Might this be the cause of the problem? How can it be fixed?

Edit: Added as this also applies to the new VS version.

解决方案

The function std::mem_fun is defined in the header <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. This is not exclusive to VS; it was also true for older gcc versions, like 4.0. Newer compilers are more standard-conforming and will require you to #include the actual headers that define standard library functions and classes.

这篇关于'mem_fun':不是'std'的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆