【问题标题】:C++ IntelliSense error with standard template library: <error-type>*?标准模板库的 C++ IntelliSense 错误:<error-type>*?
【发布时间】:2014-06-14 14:31:02
【问题描述】:

我正在使用 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

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

【问题讨论】:

  • class FooMessage嵌套 本地类吗?
  • 如果您的代码可以编译,我不会太担心 Intellisense 错误。这对我来说几乎总是错的。

标签: c++ iterator intellisense standard-library


【解决方案1】:

你的方法应该被实现为

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]);
}

在此处查看在线代码 sn-p http://ideone.com/YZL6Uv

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

【讨论】:

    猜你喜欢
    • 2013-04-16
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 2011-09-30
    • 1970-01-01
    • 2013-04-05
    相关资源
    最近更新 更多