包含文件的奇怪问题 [英] Strange problem with include file

查看:77
本文介绍了包含文件的奇怪问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
我正在Visual Studio 2008中从事一个项目.它有50多个类,分为文件夹和子文件夹.除两行外,所有内容都编译良好:

Hello!
I am working on a project in Visual Studio 2008. It has over 50 classes divided in folders and subfolders. Everything compiled nicely except two lines:

RandomTimedFlowElement.cpp
d:\c++_projects\projekat2010\pr2010\projekat_2010_1.0\concepts\abstract concepts\randomtimedflowelement.cpp(22) : error C2653: 'Event' : is not a class or namespace name
d:\c++_projects\projekat2010\pr2010\projekat_2010_1.0\concepts\abstract concepts\randomtimedflowelement.cpp(22) : error C3861: 'create': identifier not found



事件类在Event.h中,而create()是事件类中的静态函数.
这很奇怪,因为我定期包含此类,而此cpp文件看不到它.它们不在同一个文件夹中,但是当它们都没问题时.
那么,由于我无法移动.h文件,该怎么办?在其他一些班级也需要它.我设置了包含路径,但问题仍然存在.
为什么编译器不只是说:Event.h无法打开这样的文件或目录...而是给了我这些错误.
请帮忙.
这是RandomTimedFlowElement.cpp:



Event class is in Event.h and create() is static function in Event class.
This is strange because I included this class regularly and this cpp file doesn''t see it. They are not in the same folder but when they are everything is OK.
So what should I do because I can''t move .h file? It is needed in some other class also. I set include paths but the problem remains.
Why compiler doesn''t just say: Event.h cannot open such file or directory ... but gives me these errors.
Please help.
This is the RandomTimedFlowElement.cpp:

// Class RandomTimedFlowElement 


#include "RandomTimedFlowElement.h"
// Event
#include "Event.h"

RandomTimedFlowElement::~RandomTimedFlowElement ()
{

}

// Other Operations (implementation)
void RandomTimedFlowElement::raiseEvent (ID id)
{
	Time tm = 0;
	tm = getTime(id);
	Event::create(this,tm,id);
}

推荐答案

此文件一定看不到您的包含文件,请确保在此文件中使用正确的相对路径将其包括在内.
This one file must not be seeing your include file, make sure you include it using a correct relative path, in this file.


#include "RandomTimedFlowElement.h"
// Event
#include "Event.h"



您在RandomTimedFlowElement.h中拥有什么,请检查所有定义.可能是那里有些东西弄乱了.我看到过这样的情况,其中某些在头文件中未完成的定义会引起奇怪的问题.


如果将其更改为
会发生什么?



What do you have in RandomTimedFlowElement.h, check all your definitions. May be some thing is messed up there. I have seen cases where some definiton that is not complete in header file will cause strange problems.


What happens if you change it to

// Event
#include "Event.h"

#include "RandomTimedFlowElement.h"


Event.h实际上是一个非常流行的文件名.确保您包括正确的人.

也可能是您的两个包含的头文件具有相同的包含保护,例如
Event.h is actually a very popular name for a file. Make sure you are including the correct one.

It could also be that your two included header files have the same include guard like
#ifndef FILE_H
#define FILE_H
(declaration)
#endif


并非罕见的副本&粘贴问题.


A not so uncommon copy & paste problem.


这篇关于包含文件的奇怪问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆