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

error: no type named ‘value_type’ in ‘class

本文关键字:value type 类型 错误      更新时间:2023-10-16

我收到以下编译器错误:

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);
  };  
}

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

相关文章: