簡體   English   中英

標准模板庫的C ++ IntelliSense錯誤: <error-type> *?

[英]C++ IntelliSense error with standard template library: <error-type>*?

我正在使用Visual Studio開發游戲對象的消息傳遞系統,但遇到了奇怪的強制轉換錯誤。 當我調用接受迭代器作為參數的方法時,就會發生這種情況。 調用來自具有成員變量的類中:

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

我在Message類中定義了一個方法,如下所示:

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

方法調用本身看起來像(ID是一個無符號的int變量):

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

您可以發布更多代碼嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM