Undeclared Identifier

Hi I'm having a problem with an undeclared identifier error.

I can't seem to find out why
<
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "Edge.h"

using namespace std;



template <class type>

class Vertex
{
private:
string name;
type data;


public:


Vertex(string name, type data)
{
this->name = name;
this->data = data;

}
class Adj_List
{
public:
vector <Edge>edges;
};






};
>

and

<
#pragma once
#include <iostream>
#include <string>
#include "Vertex.h"

using namespace std;

template <class type>

class Edge
{
private:
double weight;
Vertex<type> * next_vertex;


public:
Edge(double weight, Vertex<type> next_vertex )
{
this->weight = weight;
this->next_vertex = &next_vertex;

}

Vertex<type>* getnext() { return next_vertex; }


};



>
The error is at vector <Edge> edges;
Hi,
Declare a Edge class prototype in vertex.h :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "Edge.h"

using namespace std;
template <class type>
class Edge;

template <class type>
class Vertex
{
private:
string name;
type data;
public:
Vertex(string name, type data)
{
this->name = name;
this->data = data;
}
class Adj_List
{
public:
vector <Edge>edges;
};
};

In class Adj_List :

1
2
3
4
5
class Adj_List
{
public:
vector <Edge>edges;
}


This line can also potentially cause compiler errors, because it requires the class Edge to be fully defined. Move its class definition to a source file to fix them :

1
2
3
4
5
6
7
 // somecpp.cpp
template <class type>
class Vertex::Adj_List
{
public:
vector <Edge>edges;
}


And in the header, declare the Adj_List class as a prototype :
class Adj_List;
Does that help you? :)
Topic archived. No new replies allowed.