使用运算符++和-使用vs 2017提高bimap迭代器错误

时间:2018-06-25 04:06:24

标签: c++ boost boost-bimap

我从boost bimap示例中得到了示例。
我在vs2017中提出了解决方案,并包含了boost文件。
使用迭代器时,intellisense在for语句中显示++运算符错误。
但我忽略了智能感知,并且代码可以很好地编译。

当我尝试对迭代器使用“-”运算符以获取先前的迭代器时,代码根本无法编译,从而给我带来相同的智能错误。

第一个错误是“表达式必须具有指针类型”。
第二个错误是没有运算符“ ++”与这些操作数匹配。

带有很长的复杂错误消息,我根本听不懂。
这是代码的一部分:

// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

//  VC++ 8.0 warns on usage of certain Standard Library and API functions that
//  can be cause buffer overruns or other possible security issues if misused.
//  See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
//  But the wording of the warning is misleading and unsettling, there are no
//  portable alternative functions, and VC++ 8.0's own libraries use the
//  functions in question. So turn off the warnings.
//#define _CRT_SECURE_NO_DEPRECATE
//#define _SCL_SECURE_NO_DEPRECATE

// Boost.Bimap Example
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include <boost/config.hpp>

#include <iostream>
#include <cassert>

// A convinience header is avaiable in the boost directory:
#include <boost/bimap.hpp>

int main()
{
    //[ code_step_by_step_definition

    typedef boost::bimap< int, std::string > bm_type;
    bm_type bm;
    //]

    //[ code_step_by_step_set_of_relations_view

    bm.insert(bm_type::value_type(1, "one"));
    bm.insert(bm_type::value_type(2, "two"));

    std::cout << "There are " << bm.size() << "relations" << std::endl;

    for (bm_type::const_iterator iter = bm.begin(), iend = bm.end();
        iter != iend; ++iter)
    {
        // iter->left  : data : int
        // iter->right : data : std::string
        if (iter == (bm.end() - 1))
        {
            std::cout << iter->left << " <--> " << iter->right << std::endl;

        }
        std::cout << iter->left << " <--> " << iter->right << std::endl;

    }
}

我在做什么错??

我现在尝试避免使用“-”,而是使用rbegin():

if (iter == bm.rbegin())

但是它给出了类似的错误,但是对于“ ==”,
错误是没有运算符“ ==”与这些操作数匹配。

0 个答案:

没有答案