1

在构建使用 tinyXml2 的项目后,我收到以下三个错误。错误显示在所附图像中。有问题的代码可以在 tinyXml2 的 xtree.cs 文件中找到,这里:

template<class _Iter>
    void insert(_Iter _First, _Iter _Last)
    {   // insert [_First, _Last) one at a time
    _DEBUG_RANGE(_First, _Last);
    for (; _First != _Last; ++_First)
        {   // insert element as lvalue
        const value_type& _Val = *_First;
        insert(end(), _Val);
        }
    }

tinyXml2_Errors

我正在使用(并且必须继续使用)VS2010

什么可能导致这些错误?

1) 错误 C2675:一元 '++':'std::string' 未定义此运算符或转换为预定义运算符可接受的类型

2)错误C2100:非法间接

3) 错误 C2440: 'initializing': 无法从 'std::string' 转换为 'const std::pair<_Ty1,_Ty2> &'

编辑:包含错误

4

1 回答 1

0

我评论了类(和标题)中的所有内容并添加了代码,直到收到错误。这个失败实际上不是由于 tinyXml2 - 它是在映射中插入字符串失败。

对于将来遇到此问题的任何其他人,这是有问题的函数,它在 Visual Studio 中不会生成波浪形的红线。

    map<string, string> createMap(CNintendoItem ni)
    {
    map<string, string> xmlNodeToValue;

    //ItemName is a string constant. ni.Name is a string returned from a class
    xmlNodeToValue.insert(ItemName, ni.Name);//name of the item

    ...//several more insertions

    return xmlNodeToValue;
}

解决此问题的一种方法是使用以下方法为新键分配值:

xmlNodeToValue[ItemName] = ni.Name;//name of the item
于 2017-02-05T03:20:24.537 回答