针对多个复制构造函数的编译器警告
Compiler warning for multiple copy constructors
我想使用自定义类作为boost::heap::fibonacci_heap的类型,并且还能够迭代和修改堆的元素。我正在试验如何有序地遍历Boost提供的代码。堆优先级队列和更新给定的元素?.
我已经提出了一个工作的例子,但是我的Visual Studio 2010编译器警告我,我的类EdgeHeap有多个复制构造函数(警告文档)。
下面是警告(大致):
filepathboostheapfibonacci_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;
});
}
看头文件,boost::heap::fibonacci_heap
确实有多个复制构造函数:
fibonacci_heap(fibonacci_heap const &);
fibonacci_heap(fibonacci_heap &);
(编译器消息不是关于EdgeHeap
或您的类型之一)
根据VS文档,这是一个信息警告,在这种情况下不用担心。
相关文章:
- 如何修复编译器警告 C6386 和 C6385?
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 为什么布尔开关语句有编译器警告?
- 使用 reverse_iterator 而不是const_reverse_iterator并获得讨厌的编译器警告和错误
- 来自 std::chrono 的编译器警告,但未被使用
- 警告级别为 3 的 int 的 std::vector push_back 处的编译器警告
- 有没有办法在从临时返回按值string_view时获得编译器警告?
- 常量更改而不const_cast<> 为什么没有编译器警告/错误?
- C++ 添加编译器警告,以错误使用自定义打印/日志功能
- 我正在尝试在我的类中创建一个静态成员,但编译器警告我它是未定义的
- 是否可以将移动的变量标记为不再可用,并在使用它时收到编译器警告?
- 为什么我应该始终启用编译器警告
- 对列表类中的泛型方法禁用编译器警告 2100,该泛型方法可能包含指针,也可能不包含指针
- C++ 如何禁用具有不同符号变量比较的特定行的编译器警告?
- CMake:如何将每个资源编译器警告视为错误并抑制特定警告?
- 为什么方法重载或枚举标志定义会触发 gcc7.2 编译器警告?
- 违反严格别名并不总是会产生编译器警告
- (如何)获取有关某个 C++Year 的已弃用/不推荐的功能/构造的编译器警告
- 使用 VS 2015 的编译器警告 4456
- 在嵌套名称说明符中使用枚举(编译器警告)