我试图从Graphviz DOT文件中读取图形.我对Vertex的两个属性感兴趣 - 它的id和外围.A还想加载图形标签.
我的代码看起来像这样:
struct DotVertex {
std::string name;
int peripheries;
};
struct DotEdge {
std::string label;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
DotVertex, DotEdge> graph_t;
graph_t graphviz;
boost::dynamic_properties dp;
dp.property("node_id", boost::get(&DotVertex::name, graphviz));
dp.property("peripheries", boost::get(&DotVertex::peripheries, graphviz));
dp.property("edge_id", boost::get(&DotEdge::label, graphviz));
bool status = boost::read_graphviz(dot, graphviz, dp);
Run Code Online (Sandbox Code Playgroud)
我的示例DOT文件如下所示:
digraph G {
rankdir=LR
I [label="", style=invis, width=0]
I -> 0
0 [label="0", peripheries=2]
0 -> 0 [label="a"]
0 -> 1 [label="!a"]
1 [label="1"]
1 -> 0 [label="a"]
1 -> 1 [label="!a"]
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到异常"Property …
我有一段代码,它应该声明基础结构,然后声明继承它的模板结构.然后结构部分被证明.
#include <utility>
#include <iostream>
template<class A, class B>
struct Parent {
std::pair<A, B> m_pair;
void print() {
std::cout << m_pair.first << ", " << m_pair.second << "\n";
}
};
template <class A, class B>
struct Some : public Parent<A, B> {
Some(A a, B b) : Parent<A, B>({ {a, b} }) {}
void add() {
m_pair.first += m_pair.second;
}
};
template <class B>
struct Some<B, float> : public Parent<B, float> {
Some(B a, float b) : Parent<B, float>({ {a, …Run Code Online (Sandbox Code Playgroud)