Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: no type named ‘value_type’ in ‘class

Tags:

c++

templates

I am getting the following compiler error:

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

What does this mean?

The following line gives me a whole slew of compiler errors

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);
  };  
}
like image 495
Matthew Hoggan Avatar asked Apr 08 '12 18:04

Matthew Hoggan


1 Answers

The comparison class should be the 3rd parameter of the std::priority_queue template, the second being a container (like std::vector<typename Graph::graph<U>::vertex>) which will have a value_type member.

like image 143
alexisdm Avatar answered Oct 05 '22 09:10

alexisdm