Я получаю ошибку ниже по реализации моего класса Vertex в MyFile.h и MyFile.ccC++ вопрос заголовка и .cc файл с членом класса
// MyFile.h
#ifndef FILE
#define FILE
#include <set>
class Vertex{
public:
int i, j;
set<Vertex*> adj; //references to adjacent vertices (max of 4)
Vertex();
~Vertex();
//end constructors
void setPos(int row, int col);
/** must overload for set<Vertex> to function */
const bool operator < (const Vertex &o) const;
};//END class Vertex
#endif
// MyFile.cc
#include "MyFile.h"
#include <set>
using namespace std;
Vertex::Vertex():i(-1), j(-1), adj(0,5)/*may store [0,4] elements*/{}
Vertex::~Vertex(){
adj.clear();
}
//end constructors
void Vertex::setPos(int row, int col){
i = row;
j = col;
}//end setPos()
/** must overload for set<Vertex> to function */
const bool Vertex::operator < (const Vertex &o) const{
if(i < o.i)
return true;
if(i > o.i)
return false;
return j < o.j;
}
/** connect v1 and v2 such that they are adjacent */
void addEdge(Vertex* v1, Vertex* v2){
v1->adj.insert(v2);
v2->adj.insert(v1);
}//end addEdge
Я попробовал несколько способов реализации класса, но Я постоянно получаю эту ошибку:
In file included from MyFile.cc:5:0:
MyFile.h:15:2: error: 'set' does not name a type
set<Vertex*> adj; //references to adjacent vertices (max of 4)
^
MyFile.cc: In constructor 'Vertex::Vertex()':
MyFile.cc:15:32: error: class 'Vertex' does not have any field named 'ad
j'
Vertex::Vertex():i(-1), j(-1), adj(0,5)/*may store [0,4] elements*/{}
^
MyFile.cc: In destructor 'Vertex::~Vertex()':
MyFile.cc:18:2: error: 'adj' was not declared in this scope
adj.clear();
^
MyFile.cc: In function 'void addEdge(Vertex*, Vertex*)':
MyFile.cc:39:6: error: 'class Vertex' has no member named 'adj'
v1->adj.insert(v2);
^
MyFile.cc:40:6: error: 'class Vertex' has no member named 'adj'
v2->adj.insert(v1);
^
make: *** [MyFile.o] Error 1
Может быть, есть что-то я пропускаю, потому что я все еще учусь, как эффективно использовать файлы заголовков. Может ли кто-нибудь дать мне какие-нибудь предложения?
В определении вашего класса 'std :: set adj;'. И используйте что-то другое, кроме 'FILE' для защитника включения - это рецепт катастрофы. –