I'm starting to develop a list of lists to represent a graph in memory.
I just did this first part and am getting the following error:
class std::vector<No> has no member named 'getId'
Follow my code so far ...
main.cpp:
#include <iostream>
using namespace std;
int main()
{
return 0;
}
no.h:
#ifndef NO_H_INCLUDED
#define NO_H_INCLUDED
#include <vector>
#include "Aresta.h"
using namespace std;
class No{
private:
int id;
vector<Aresta> *adjNo;
public:
No(int id);
int getId();
vector<Aresta>* getAdjNo();
void inserirAdj(Aresta aresta);
int totalAdjacencias();
};
#endif // NO_H_INCLUDED
no.cpp:
#include "No.h"
#include <vector>
No::No(int id){
this->id=id;
this->adjNo = new vector<Aresta>;
}
int No::getId(){
return this->id;
}
vector<Aresta>* No::getAdjNo(){
return this->adjNo;
}
void No::inserirAdj(Aresta aresta){
adjNo->push_back(aresta);
}
int No::totalAdjacencias(){
this->adjNo->size();
}
Edge.h:
#ifndef ARESTA_H_INCLUDED
#define ARESTA_H_INCLUDED
class Aresta{
private:
int id;
int peso;
public:
Aresta(int id, int peso);
int getId();
};
#endif // ARESTA_H_INCLUDED
aresta.cpp:
#include "Aresta.h"
Aresta::Aresta(int id, int peso){
this->id=id;
this->peso=peso;
}
int Aresta::getId(){
return this->id;
}
Graph.h:
#ifndef GRAFO_H_INCLUDED
#define GRAFO_H_INCLUDED
#include "No.h"
using namespace std;
class Grafo{
private:
vector<No> *listNos;
public:
Grafo();
void addNo(int id);
bool existeNo(int id);
};
#endif // GRAFO_H_INCLUDED
grafo.cpp:
#include "Grafo.h"
#include <iostream>
Grafo::Grafo(){
listNos = new vector<No>;
}
void Grafo::addNo(int id){
if(!existeNo(id)){
No noAux(id);
listNos->push_back(noAux);
} else
cout << "No ja existe no Grafo";
}
bool Grafo::existeNo(int id){
for(int i=0; i < listNos->size(); i++){
if(listNos[i].getId() == id)
return true;
}
return false;
}