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