相关疑难解决方法(0)

本地类型作为C++中的模板参数

这是我的代码

#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++ templates

36
推荐指数
2
解决办法
2万
查看次数

如何创建C++ Boost无向图并以深度优先搜索(DFS)顺序遍历它?

如何创建C++ Boost无向图并以深度优先搜索(DFS)顺序遍历它?

c++ boost-graph

29
推荐指数
1
解决办法
1万
查看次数

具有VertexList的Dijkstra最短路径=增强图中的ListS

我对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)

c++ boost graph dijkstra

9
推荐指数
2
解决办法
6443
查看次数

Boost Graph Library:顶点滤波图上的BFS?

我正在尝试编写一个广度优先搜索版本,它只搜索我给定图形的子图.为此,我正在尝试使用filtered_graphBoost BGL中的类.

在尝试这样做时,我遇到了巨大的,丑陋的模板类型错误.

我在想:

  1. 如何将v原始图形中的起始顶点转换为滤波图形中的顶点?
  2. 我的访客类型应该是什么样的BFS?它是否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)

c++ templates boost graph boost-graph

2
推荐指数
1
解决办法
505
查看次数

标签 统计

c++ ×4

boost ×2

boost-graph ×2

graph ×2

templates ×2

dijkstra ×1