Boost Djikstra 类 "boost::p roperty_map> 没有成员 "type"
Boost Djikstra class "boost::property_map> has no member "type"
一段时间以来,我一直在努力使用 Boost 框架实现 Djikstra 的算法,但我似乎无法弄清楚我错过了什么。
使用在以下位置找到的示例: https://www.boost.org/doc/libs/1_67_0/libs/graph/doc/dijkstra_shortest_paths.html,
我在第 36 行收到错误
property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, g);
class "boost::property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS>, boost::edge_weight_t, void>" has no member "type"
我找不到其他人有同样的问题,而且我似乎无法弄清楚问题是什么。关于这个问题的任何帮助将不胜感激。
提前致谢
问题可能是您未能在图形上定义边权重属性。 例如:
住在科里鲁
using graph_t = boost::adjacency_list</*boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property*/>;
boost::property_map<graph_t, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g);
不编译。您应该添加一个:
住在科里鲁
#include <boost/graph/adjacency_list.hpp>
using graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
boost::no_property,
boost::property<boost::edge_weight_t, double> >;
int main() {
graph_t g(5);
boost::property_map<graph_t, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g);
}
您可能可以简化一点:
auto weightmap = get(boost::edge_weight, g);
或者考虑使用捆绑属性:
住在科里鲁
#include <boost/graph/adjacency_list.hpp>
struct EdgeProps {
double weight = 0.0;
};
using graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, boost::no_property, EdgeProps>;
int main() {
graph_t g(5);
auto weightmap = get(&EdgeProps::weight, g);
}
相关文章:
- EASTL矢量<向量<int>>连续的
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 控制到达非空函数clang(-Wreturn-type)的末尾
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 将系数存储在头文件的数组中("does not name a type"错误)
- 尝试打开 ifstream 时出现"Incomplete type"错误
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型
- "Missing type specifier - int assumed"无法通过向主函数添加"return 0"来解决
- OpenCV CV_16F type
- C++ "错误:在'类 std::result_of< ... >"中没有名为'type'的类型"
- 将内存分配返回值强制转换为 TYPE 数组
- C++ 一个lambda浅拷贝const Type&如果它被赋予一个命名捕获,如[copy=val](){}?
- reference_wrapper导致"incomplete type is not allowed"
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 如何解决"'mutex' in namespace 'std' does not name a type"?