gpt4 book ai didi

c++ - 匹配通用优先级队列类型的函数参数

转载 作者:行者123 更新时间:2023-11-28 00:41:20 26 4
gpt4 key购买 nike

我使用一个提供通用优先级队列类型实现的外部库。优先级队列的类(在头文件中声明,称之为priorityQueue.h)是

template <typename KeyType, typename DataType, template <typename datatype> class   StorageType>
class PriorityQueue {...};

其中包含一个插入函数:

//Insert a key-value pair to the priority queue
void insert( const KeyType& key, const DataType& data, const DescriptorType ptr = 0)

我需要这个优先级队列来将以下结构的项目存储到:

 struct certificate
{
float tfail;
typename GraphType::NodeIterator n;
unsigned int ne, citem;
};

所以我实现了这个功能:

void storeCertificates(const NodeIterator& u, int node_or_edge)
{
//representation: (ne, idn, tfail), for a node identified by idn if we have a min cert (ne= 0), or a tail of an edge identified by idn if we have a pr cert (ne=1)
certificate cert;

int ne;
if(node_or_edge == 0) //min certificate
ne = 0;
else //prim certificate
ne = 1;

cert.ne = ne;
cert.n = u;
cert.tfail = u->tfail;
cert.citem = 0;

c.insert( cert.tfail, cert, cert.citem); //<=========
}

将证书项存储到定义为的优先级队列中:

 typedef PriorityQueue< WeightType, NodeIterator, HeapStorage>   PriorityQueueType;
PriorityQueueType c;

在编译时,我得到以下错误:

td_dijkstra_and_os.h:680:2: error: function does not match call to  
‘PriorityQueue<float, std::_List_iterator<ALNode<node, edge> >, HeapStorage>::insert(float&, TD_Dijkstra_OS<DynamicGraph<AdjacencyListImpl, node, edge> >::certificate&, unsigned int&)’
td_dijkstra_and_os.h:680:2: note: candidate is:
/home/danuser/eCOMPASS/pgl/include/Structs/Trees/priorityQueue.h:132:10: σημείωση: void PriorityQueue<KeyType, DataType, StorageType>::insert(const KeyType&, const DataType&, PriorityQueue<KeyType, DataType, StorageType>::DescriptorType) [with KeyType = float, DataType = std::_List_iterator<ALNode<node, edge> >, StorageType = HeapStorage, PriorityQueue<KeyType, DataType, StorageType>::DescriptorType = unsigned int*, PQSizeType = unsigned int]
/home/danuser/eCOMPASS/pgl/include/Structs/Trees/priorityQueue.h:132:10: σημείωση: no known conversion for argument 2 from ‘TD_Dijkstra_OS<DynamicGraph<AdjacencyListImpl, node, edge> >::certificate’ to ‘const std::_List_iterator<ALNode<node, edge> >&’

请为我的实现提供使用此插入功能的正确方法。

编辑:有人可以通过使用 std::priority_queue 或更好的 boost 优先级队列来实现吗?

最佳答案

队列的

DataTypeNodeIterator,但您正在尝试插入 certificate

关于c++ - 匹配通用优先级队列类型的函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18726774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com