-4

I am having trouble with defining a variable for my C++ university assignment:

#include "graph.h"
#include <string>
#include <iomanip>
#include <iostream>
#include <stack>
//using namespace std;
/* instance field for the number of vertices in the graph*/

const float INFINITY = 0;

The errors I am getting are:

Error 1 error C2062: type 'float' unexpected
      2 IntelliSense: expected an identifier
      3 IntelliSense: function "<error>" may not be initialized

All to do with the INFINITY line, what am I doing wrong?

Edit: this is the header file for the class

#include <queue>
#include <set>
#include <iostream>

#ifndef _graph_h
#define _graph_h

#include "edge.h"
#include "vertex.h"
#include "disjoint.h"

using namespace std;

class Graph
{
public:

 /*Constructor sets the number of vertices in
 this Graph. Initialises the two dimensional
 array of weights by setting all values to
 INFINITY (some value larger than any
 possible edge weight) except the diagonal of
 the array where the weight is set to 0.*/

 Graph(unsigned int);

 //decon
 ~Graph();

  /*Adds pointer to Vertex to the collection of    
  vertices for this Graph.*/ 
  void addVertex(Vertex*);

 /* Accessor returns a pointer to the Vertex
 with the identifier/index in the parameter*/
 Vertex* getVertex(int);

 /* Adds pointer to Edge to the edge list for this
 Graph. Using the source and destination
 identifiers from the edge, sets the weight of
 the undirected edge in the adjacency matrix. */
 void addEdge(Edge*);

 /*Uses Kruskal’s algorithm to find the
 Minimum Spanning Tree (MST) for this
 Graph. Stores the edges of the MST in the
 adjacency list of each Vertex. Returns the
 cost of the minimum spanning tree.*/
 double minimumSpanningTreeCost();

 /*Determines the shortest path from the source
 vertex to all other vertices. Prints the length
 of the path and the vertex identifiers in the
 path */
 void dijkstra(unsigned int);

 /*Determines the shortest path from the source
 vertex to all other vertices using only the
 adjacencies in the minimum spanning tree.
 Prints the length of the path and the vertex
 identifiers in the path.*/
 void bfs(unsigned int);

 /*Outputs the adjacency matrix for the graph.
 If an edge weight is INFINITY, - should be
 printed instead of a number.*/
 friend ostream& operator<<(ostream&, Graph&);

 void TempDisplay();
private:
 /* instance field for the number of vertices in the graph*/
 unsigned int numVertices;
 /*the adjacency matrix for this graph. two dimensional array of weights*/
 double** weights;
 /*Storage for edges to be used by Kruskal’s
 algorithm for calculating the minimum cost
 spanning tree.*/
 priority_queue<Edge*,vector<Edge*>, Edge> edges;
 /*store graph vertices*/
 /// adjacency list... initialise to empty
 vector<Vertex*> vertices;

};
#endif // _graph_h
Rakib
  • 7,435
  • 7
  • 29
  • 45
joelwmale
  • 121
  • 1
  • 3
  • 10

1 Answers1

1

You should check whether the error arises from some problems in "graph.h", for example by commenting it out.

andreee
  • 4,459
  • 22
  • 42
  • Commenting it out fixes the error, but causes more errors in my program (as the program uses it) – joelwmale May 27 '14 at 15:08
  • Yes of course. This was meant to locate the error. I am quite sure that your error is located in the header file, not in the code you posted. So maybe you could update your question and perhaps post your header file code. Btw. why am I getting -1 for that? – andreee May 27 '14 at 15:10
  • Not sure, i updated my post with the header file. – joelwmale May 27 '14 at 15:13