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;
});
}
컴파일러 메시지에 붙여 넣으면 도움이됩니다 –
거친 텍스트를 추가했습니다. 나는 독일어로 번역했기 때문에 정확한 영어 컴파일러가 아닐 수도 있습니다. – Cecilia