错误:"类名"未命名类型

Error : 'ClassName' does not name a type

本文关键字:类型 未命名 类名 错误      更新时间:2023-10-16

我知道这个错误是不言自明的,但我似乎无法在我的代码中找到内部问题。对我来说,一切似乎都很好。无论如何,有我的头文件:

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(我不知道是否需要。这只是一个简单的主要检查代码):

#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;
}

当我尝试编译时,我收到以下错误:

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 源文件正在工作,因为在不同的主文件中,我得到了我期望的结果,所以我猜我缺乏关于正向声明的知识或缺少一些真正基本的东西。

附注:I没有找到发布.cpp文件的充分理由,因为它是包含错误。

您的包含守卫似乎存在(复制/粘贴?在GList.h应该有

#ifndef GLIST_H_
#define GLIST_H_
...
#endif

并在VList.h

#ifndef VLIST_H_
#define VLIST_H_
...
#endif