多个拷贝构造函数的编译器警告

时间:2014-06-17 12:45:09

标签: c++ visual-studio-2010 templates constructor

我想使用自定义类作为boost :: heap :: fibonacci_heap的类型,并且还能够迭代和修改堆的元素。我正在试验How to orderly traverse a Boost.Heap Priority Queue and update a given element?提供的代码。

我已经提出了一个工作示例,但是我的Visual Studio 2010编译器警告我,我的类EdgeHeap有多个复制构造函数(warning documentation)。

这里是警告(大致):

filepath\boost\heap\fibonacci_heap.hpp(762): warning C4521: 'boost::heap::fibonacci_heap<T>': Multiple constructors
          with
          [
              T=EdgeHeap
          ]

我很困惑,因为我还没有声明任何复制构造函数,因此唯一应该是编译器自动添加的复制构造函数。多个构造函数来自哪里?这也是我应该担心的事情吗?

#include <iostream>
#include <algorithm>
#include <boost/heap/fibonacci_heap.hpp>

class Edge
{
    public:
        int index;
        double weight;
        std::pair<int, int> vertices;

        Edge(int i, double w, int start, int end)
        {
            index = i;
            weight = w;
            vertices.first = start;
            vertices.second = end;
        }
};

class EdgeHeap
{
    typedef boost::heap::fibonacci_heap<EdgeHeap>::handle_type handle_t;

    public:
        handle_t handle;
        Edge data;

        EdgeHeap(const Edge &data_) : data(data_) {}

        bool operator<(EdgeHeap const & rhs) const
        {
            return data.weight < rhs.data.weight;
        }
};

void setup_handle(boost::heap::fibonacci_heap<EdgeHeap>::handle_type &&handle)
{
    (*handle).handle = handle;
}

int main()
{
    boost::heap::fibonacci_heap<EdgeHeap> heap;

    Edge e(0, 10, 0, 1);
    setup_handle(heap.push(e));
    Edge e1(1, 2, 1, 2);
    setup_handle(heap.push(e1));
    Edge e2(2, 80, 2, 0);
    setup_handle(heap.push(e2));

    std::find_if(heap.ordered_begin(), heap.ordered_end(),
    [&heap](const EdgeHeap &e) -> bool
    {
        if(e.data.index == 2)
        {
            const_cast<EdgeHeap &>(e).data.weight += 2;
            heap.increase(e.handle);
            return true;
        }
        return false;
    });

    std::for_each(heap.ordered_begin(), heap.ordered_end(),
    [](const EdgeHeap &e)
    {
        std::cout << e.data.weight << std::endl;
    });
}

1 个答案:

答案 0 :(得分:1)

查看标题,boost::heap::fibonacci_heap does have multiple copy constructors

fibonacci_heap(fibonacci_heap const &);
fibonacci_heap(fibonacci_heap &);

(编译器消息不是EdgeHeap或其中一种类型)

根据VS documentation,这是一个信息警告,在这种情况下无需担心。