[英]Error : 'ClassName' does not name a type
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 : 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 : 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 : 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 : 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) : 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;
}
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. VList和VNode源文件正在工作,因为在另一个主目录中,我得到了预期的结果,所以我想我缺少关于前向声明的知识或缺少真正重要的东西。
PS:I didn't find a good reason to post .cpp files since it's inclusion error. PS:我找不到发布.cpp文件的充分理由,因为这是包含错误。
It seems there's a (copy/paste?) problem with your include guards. 您的包含卫士似乎存在(复制/粘贴?)问题。 In
GList.h
there should be 在
GList.h
中应该有
#ifndef GLIST_H_
#define GLIST_H_
...
#endif
and in VList.h
并在
VList.h
#ifndef VLIST_H_
#define VLIST_H_
...
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.