编译器(VC8)错误是:
错误C2680:'std :: _ Tree :: iterator':dynamic_cast的目标类型无效
模拟错误的源代码:
[EDIT]源现已修复

#include <map>
#include <string>

struct tag_data
{
    int in;
    int on;
    std::string sn;
};

class myclass
{
private:
    typedef std::map<std::string, tag_data> TypeData;
    TypeData MapStorage;
    typedef std::map<unsigned long, TypeData::iterator > TypeToThreadIterMapStorage;
    TypeToThreadIterMapStorage ThreadIterMapStorage;

public:
    bool find( std::string& k)
    {
        TypeData::const_iterator theData ;
        theData = MapStorage.find(k);
        //ThreadIterMapStorage [ 0 ] = MapStorage.begin();// this is ok
        ThreadIterMapStorage [ 1 ] = dynamic_cast<TypeData::iterator>(theData); // the error occurs here
        return theData != MapStorage.end();
    }

    virtual ~myclass(){}
};

int _tmain(int argc, _TCHAR* argv[])
{
    myclass mc;
    return 0;
}

最佳答案

是什么让您认为TypeData :: iterator和TypeData :: const_iterator甚至相关?

为什么不将'theData'的类型更改为迭代器?

TypeData::iterator theData = MapStorage.find(k);

09-30 00:14