错误:'类中没有名为'value_type'的类型

时间:2012-04-08 18:32:44

标签: c++ templates

我收到以下编译器错误:

graph_algorithms.h:59:111: error: no type named ‘value_type’ in ‘class Graph::graph_algorithms<int>::vertex_comparer’

这是什么意思?

以下行给出了一大堆编译器错误

std::priority_queue<typename Graph::graph<U>::vertex, typename Graph::graph_algorithms<U>::vertex_comparer> pri_que;

#ifndef GRAPH_ALGORIUHMS_H_
#define GRAPH_ALGORIUHMS_H_

#include <queue>
#include "graph.h"

namespace Graph
{
  template <class U>
  class graph_algorithms
  {
  // Forward declarations of 
  // internal classes
  private :
    class vertex_comparer;

  public :
    graph_algorithms(graph<U> &graph) :
      m_Graph(graph)
    {}  
  // List of algorithms to perform on graph
  typename std::queue<U> &find_key_breadth_first(U key);

  // Definition of internal classes
  private :
    class vertex_comparer
    {   
    public:
      bool operator()(typename graph<U>::vertex &v1, typename graph<U>::vertex &v2)
      {   
        return (v1.key() < v2.key()) ? true : false;
      }   
    };  
  private :
    // Private member variables and methods
    graph<U> &m_Graph;
    std::queue<U> m_Queue;
    void breadth_first_search(U key);
  };  
}

1 个答案:

答案 0 :(得分:4)

比较类应该是std::priority_queue模板的第3个参数,第二个是容器(如std::vector<typename Graph::graph<U>::vertex>),它将拥有value_type成员。