Class does not name a type

I'm attempting to build a graph class and have the following Graph.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
29
30
31
32
33
#ifndef GRAPH_H  
#define GRAPH_H
#include <list>
#include <algorithm>
using namespace std;

class Graph {

public:

        Graph();

        class vertex {

                private:
                        list<vertex> adjacent;
                        bool visited;

                public:
                        vertex();
                        char label;
                        vertex* insertVertex(char x);
                        void addEdge(char v, char u);

        };

private:
         list<vertex> vertices;

};

#endif


And the Graph.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <iostream>
#include <list>
#include <algorithm>
#include "graph.h"
using namespace std;

Graph::Graph(){}

Graph::vertex::vertex(){}

vertex* Graph::vertex::insertVertex(char x){

        vertex* newVertex = new Graph::vertex();
        newVertex->label = x;
        return newVertex;
}


However, I get the error "vertex does not name a type"

I can't seem to figure out what's wrong....
Last edited on
On which line of the code? Graph.cpp:12?
For the return type you need to specify that vertex is located inside Graph.
 
Graph::vertex* Graph::vertex::insertVertex(char x){

Inside the function definiton you don't need to do this though. It's not wrong but unnecessary.
 
vertex* newVertex = new Graph::vertex();
Last edited on
Awesome! That did it.
Topic archived. No new replies allowed.