简体   繁体   中英

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

I am making a messaging system for game objects using Visual Studio, and I'm getting a strange cast error. It happens when I call a method that accepts an iterator as a parameter. The call comes from inside a class that has member variable:

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

I call a method in my Message class defined as such:

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

The method call itself looks like (ID being an unsigned int variable):

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

For some reason, I get an IntelliSense error. I know that IntelliSense is not the compiler, and in the past it has given me insane errors that weren't actually real problems. Unfortunately, the entire program is a long way from being testable without everything breaking, and I would rather like to know now if I need to redesign my entire approach. The error is:

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

According to Google search, this happens when the compiler can't tell the parameter type. Unless they did something realllllly wacky with how iterators work, I figure this has got to be Visual Studio making a fool of itself, right?

Your method should be implemented as

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

outside the class. Are you missing the Message:: ? (probably not, but I'm just asking :) ) On my system (OS X g++ 4.8) this code compiles:

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

see the online code snippet here http://ideone.com/YZL6Uv

Can you post more of your code?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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