gpt4 book ai didi

标准模板库 : *? 的 C++ IntelliSense 错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:34:34 24 4
gpt4 key购买 nike

我正在使用 Visual Studio 为游戏对象制作一个消息传递系统,但我遇到了一个奇怪的转换错误。当我调用一个接受迭代器作为参数的方法时,就会发生这种情况。该调用来自具有成员变量的类内部:

std::map<unsigned int, std::list<Foo*>::iterator> listeners;

我在我的 Message 类中调用了这样定义的方法:

static void UnRegister(unsigned int, std::list<Foo*>::iterator);

方法调用本身看起来像(ID 是一个无符号整型变量):

Message::UnRegister(ID, listeners[ID]);

出于某种原因,我收到 IntelliSense 错误。我知道 IntelliSense 不是编译器,过去它给我带来了疯狂的错误,但实际上并不是真正的问题。不幸的是,整个程序要在没有任何问题的情况下进行测试还有很长的路要走,我现在想知道是否需要重新设计我的整个方法。错误是:

IntelliSense: no suitable user-defined conversion
from "std::_List_iterator<std::_List_val<std::_List_simple_types<Foo*>>>"
to "std::_List_iterator<std::_List_val<std::_List_simple_types<<error-type>*>>>"
exists

根据 Google 搜索,当编译器无法分辨参数类型时会发生这种情况。除非他们对迭代器的工作方式做了一些非常古怪的事情,否则我认为这一定是 Visual Studio 在出洋相,对吧?

最佳答案

你的方法应该实现为

Message::UnRegister(ID, listeners[ID])

课外。您是否缺少 Message::? (可能不是,但我只是问问 :))在我的系统 (OS X g++ 4.8) 上,这段代码编译:

#include <map>
#include <list>

using namespace std;

class Foo
{
};

class Message{
public:
static void UnRegister(unsigned int, std::list<Foo*>::iterator){}
};



int main()
{
std::map<unsigned int, std::list<Foo*>::iterator> listeners;

Message::UnRegister(0, listeners[0]);
}

请在此处查看在线代码片段 http://ideone.com/YZL6Uv

你能发布更多你的代码吗?

关于标准模板库 : <error-type>*? 的 C++ IntelliSense 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23351344/

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