c++ - 错误 : 'ClassName' does not name a type

标签 c++ eclipse g++ precompiled-headers

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

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(不知道需不需要,只是一个简单的main,检查代码):

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

当我尝试编译 im 时出现以下错误:

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 源文件正在运行,因为在不同的 main 中我得到了我预期的结果,所以我猜我缺乏关于前向声明的知识或遗漏了一些真正基础的东西。

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

最佳答案

您的包含防护似乎存在(复制/粘贴?)问题。在 GList.h 中应该有

#ifndef GLIST_H_
#define GLIST_H_

...

#endif

并且在 VList.h

#ifndef VLIST_H_
#define VLIST_H_

...

#endif

关于c++ - 错误 : 'ClassName' does not name a type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35941342/

相关文章:

c++ - std::shared_ptr 为空但不为 null

c++ - 为什么不加条件 no except 呢?

java - 我的 Activity 在未输入 OnSaveInstanceState 句柄的情况下关闭

c++ - 可变参数模板 : iterate over type/template argument

android-ndk - 为 Android 构建 V8 时找不到 sys/cdefs.h

c++ - boost async_write() 和 non_blocking socket.send() 之间的区别

c++ - 如何将 C++ 类导出为 dll?

eclipse - 如何增加 Ant 'Javadoc' 任务的内存?

java - 随机化井字

c++ - C++ Cygwin 中的堆大小