智能感知预期标识符;键入' float'预期

时间:2014-05-27 15:00:51

标签: c++

我在为C ++大学作业定义变量时遇到了麻烦:

#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;

我得到的错误是:

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

与INFINITY系列有关,我做错了什么?

编辑:这是类

的头文件
#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

1 个答案:

答案 0 :(得分:1)

您应该检查错误是否来自&#34; graph.h&#34;中的某些问题,例如通过注释出来。