0

I know the error is pretty self-explanatory but I can't seem to find the inner problem in my code.All seems fine to me.Anyway there are my header files :

GList.h :

#ifndef LIST_H_
#define LIST_H_

#include "GNode.h"

class GList {
    GNode *head,*last;
    int size;
public:
    GList();
    ~GList();

    Functions();
};

#endif 

GNode.h :

#pragma once

#include "VList.h"
#include "Key.h"

class GNode
{
    Key value;
    VList *Vec_in;  // Vertex List
    VList *Vec_out;
    GNode *next, *prev;
public:
    GNode();
    GNode(Key );
    ~GNode();

    Functions();
};

VList.h :

#ifndef LIST_H_
#define LIST_H_

#include "VNode.h"

class VList {
    VNode *head,*last;
    int size;
public:
    VList();
    ~VList();

    Functions();

};

#endif 

VNode.h :

#pragma once

class Vertex;

class VNode
{
    Vertex *value;
    VNode *next, *prev;
public:
    VNode();
    VNode(Vertex *);
    ~VNode();

    Functions();
};

class Vertex {
    int trans_amount;
    VNode *Start; // The VNode that the vertex beggins from
    VNode *Dest; // the destination node that vertex ends up
public:
    Vertex();
    Vertex(int);
    ~Vertex();

    Functions();
};

main.cpp (I don't know if its needed.It's just a simple main to check the code) :

#include <iostream>
#include "GList.h"

using namespace std;

int main(int argc, char **argv) {  


    GList *list = new GList;

    for (int i = 0; i < 20; i++) {
        Key x(i);
        list->Push(x);
    }
    list->PrintList();
    delete list;

    return 0;
}

When I try to compile im getting the following errors :

In file included from GList.h:4:0,
                 from GList.cpp:1:
GNode.h:11:2: error: ‘VList’ does not name a type
  VList *Vec_in;  // Vertex List
  ^
GNode.h:12:2: error: ‘VList’ does not name a type
  VList *Vec_out;
  ^
In file included from GList.h:4:0,
                 from main.cpp:3:
GNode.h:11:2: error: ‘VList’ does not name a type
  VList *Vec_in;  // Vertex List
  ^
GNode.h:12:2: error: ‘VList’ does not name a type
  VList *Vec_out;

VList & VNode source files are working since in a different main I got the results I expected so Im guessing I lack knowledge about forward declaration or missing something really fundamental.

PS:I didn't find a good reason to post .cpp files since it's inclusion error.

Alex R.
  • 459
  • 5
  • 16

1 Answers1

3

It seems there's a (copy/paste?) problem with your include guards. In GList.h there should be

#ifndef GLIST_H_
#define GLIST_H_

...

#endif

and in VList.h

#ifndef VLIST_H_
#define VLIST_H_

...

#endif
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190