这是我的代码
#include <vector>
template <typename T, template<typename> class C = std::vector >
struct FooBar
{
/*codez*/
};
template<typename T>
struct Global{};
int main()
{
struct Local{};
FooBar<Local,Global> k;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误
template argument for ‘template<class T, template<class> class C> struct FooBar’ uses local type ‘main()::Local’
标准的哪一部分说这是错的?我正在使用gcc 4.5.1.如何使这段代码有效?
如何创建C++ Boost无向图并以深度优先搜索(DFS)顺序遍历它?
我对Boost图表很新.我试图调整一个例子来找到使用VertexList = vecS的Dijkstra最短路径算法.我将顶点容器更改为ListS.我了解到,如果我们使用listS,我们必须提供自己的vertex_index才能使算法正常工作.
int main(int, char *[])
{
typedef float Weight;
typedef boost::property<boost::edge_weight_t, Weight> WeightProperty;
typedef boost::property<boost::vertex_name_t, std::string> NameProperty;
typedef boost::property<boost::vertex_index_t, int> IndexProperty;
typedef boost::adjacency_list < boost::listS, boost::listS, boost::directedS,
NameProperty, WeightProperty > Graph;
typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
typedef boost::graph_traits <Graph>::vertex_iterator Viter;
typedef boost::property_map < Graph, boost::vertex_index_t >::type IndexMap;
typedef boost::property_map < Graph, boost::vertex_name_t >::type NameMap;
typedef boost::iterator_property_map < Vertex*, IndexMap, Vertex, Vertex& > PredecessorMap;
typedef boost::iterator_property_map < Weight*, IndexMap, Weight, Weight& > DistanceMap;
Graph g;
Vertex v0 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个广度优先搜索版本,它只搜索我给定图形的子图.为此,我正在尝试使用filtered_graphBoost BGL中的类.
在尝试这样做时,我遇到了巨大的,丑陋的模板类型错误.
我在想:
v原始图形中的起始顶点转换为滤波图形中的顶点?MyVisitor<Vertex, SubGraph>像我一样,或者我需要一个特定于过滤图形的不同顶点类型?(这SubGraph是过滤图表类型的typedef).下面是我的代码片段,它在BFS被注释掉时编译,但是当它没有被注释时会给出错误.
#include <cstdlib>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <vector>
//Adapted from http://stackoverflow.com/questions/14470566/how-to-traverse-graph-in-boost-use-bfs
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS > Graph;
typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
/**
Functor to filter vertices in a graph which are not in the given set
*/
class VertexSetFilter
{
public:
std::set<Vertex> S;
VertexSetFilter(std::set<Vertex> inputSet)
{ …Run Code Online (Sandbox Code Playgroud)