0
I’m starting to develop a list list to represent a graph in memory.
I’ve only done that first part and I’m getting the following mistake:
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.:
#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
in 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
edge.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
cpp graph.:
#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;
}
On which line of the code the error occurs?
– Luiz Vieira
It’s on the line that you have
if(listNos[i].getId() == id)
? WhylistNos
is a pointer to a vector?– Luiz Vieira