#include在其他文件中看不到标题 [英] #Include doesn't see headers in others files
问题描述
这肯定是一个棘手的问题,很抱歉浪费您的时间,但是我找不到任何解决方案(我在互联网上进行了搜索,但一无所获).
It's surely a noobish problem, I'm sorry for wasting your time, but I can't find any solution (I searched a bit on the internet, but found nothing).
我在Visual Studio 2013中有一个控制台应用程序项目,并且我有很多文件夹,其中放置了各种.h和.cpp文件.在这些文件中,我使用名称空间对类进行分组.
I have a Console Application Project in Visual Studio 2013 and I have many folders where I put various .h and .cpp files. In these files I use namespaces for grouping classes.
问题是我无法在当前.cpp或.h文件的父目录中包含标头.
The problem is that I can't include headers that are in parent directories in the current .cpp or .h file.
例如,我在名称空间A/B/C中包含的路径/a/b/c下有一个Hello类,在名称空间A/中的/a/b/下具有Hi类. B.在我的情况下,Hello类没有看到"类Hi,但是Hi类可以看到"类Hello.另外,如果我在文件夹A/d/中具有名称空间A/D的Bye类,则Bye类不会看到" Hi和Hello类,反之亦然. 我的意思是看不到"是#include找不到标题,并且当我使用使用名称空间..."时,没有父名称空间.
For example, I have a Hello class under the path /a/b/c, that is included in the namespace A/B/C, and a Hi class under /a/b/ that is in the namespace A/B. In my situation the Hello class doesn't "see" class Hi, but class Hi can "see" class Hello. Also, if I have Bye class in folder a/d/ with namespace A/D, class Bye doesn't "see" class Hi and Hello, and viceversa. What I mean for "doesn't see" is that #include doesn't find the headers and that when I use "using namespace ..." there aren't parent namespaces.
P.S.我希望我的英语是可以理解的(不是母语),并且上面我写的很清楚.
P.S. I hope my English is understandable (it's not my mother language) and that what I just wrote above is clear.
推荐答案
我找到了解决该问题的方法.我在#include字符串"../../"中用作前缀,然后可以将所有文件都包含在目录中.我不知道这是否是最好的选择,但它确实有效.
I found a solution for the problem. I used as a prefix in my #include the string "../../", then I can include all my files in my directories. I don't know if this the best thing to do, but it worked.
这篇关于#include在其他文件中看不到标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!