c++ - 多个复制构造函数的编译器警告

标签 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;
    });
}

最佳答案

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

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

(编译器消息与 EdgeHeap 或您的一种类型无关)

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

关于c++ - 多个复制构造函数的编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24264191/

相关文章:

c++ - 为什么我不能调用派生自的模板类的模板化方法

c# - 升级到 EL 5 'Microsoft.Practices.EnterpriseLibrary.Caching ..或其依赖项之一时出错

c++ - 如何对 std::tuple 中的每个元素应用 constexpr 函数?

visual-studio-2010 - DTE VS2010 解决方案中的 "Miscellaneous Files"是什么?

visual-studio - Visual Studio 2010 中的浏览器窗口?

c++ - 模板和 g++ 4.7

c++ - 给定抽象基类 X,如何创建另一个模板类 D<T>,其中 T 是从 X 派生的类的类型?

c++ - 为什么 std::copy 或 std::swap 不需要 <algorithm>?

c# - C++ 和 SharpZipLib

c++ - 我可以使用 OpenACC 并行化调用某些函数的大代码吗?