Visual Studio C ++标头和CPP链接错误

时间:2013-08-29 17:30:51

标签: c++ visual-studio-2012 include header-files

我的项目设置如下:

Header (.h) files
 ________________                 _________ 
| Main Big Class |---------------| ModuleB |
| - libraries    |   _________   | -SubMod |    
|________________|--| ModuleA |  |_________|
                    | -SubMod |       |
                    |_________|   ____|____
                         |       | SubModB |
                     ____|____   |_________|
                    | SubModA |
                    |_________|

All Code (.cpp) files have #include "Main Big Class.h"

所以在ModuleA的子模块中,他们的标题中没有任何包含,并且他们的.cpp文件中只有#em> #include“Main.h”,其中我有#includes for strings ,向量,以及我在项目中使用的所有其他内容。 在ModuleA上我有所有它的子模块的包含,我能够在ModuleA的任何子模块中使用向量和字符串。

现在我正在转向ModuleB,我添加了一个新的子模块并且像以前一样做了,ModuleB有:

#include "SubModuleB1.h"
#include "SubModuleB2.h"

但是当我尝试编译时,Visual Studio在B中显示这些子模块中的字符串和向量的行上显示错误。

有时对行进行注释,编译,然后取消注释它们可能会编译,但我必须逐行执行此操作并且单个错误意味着它将无法编译,除非我再次对它们进行注释。

我已经尝试过清理和重建,没有用,我不知道为什么会这样。

为什么会发生这种情况,我该如何解决?

修改:错误是每行3个:

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'

1 个答案:

答案 0 :(得分:0)

在cpp文件中,添加以下内容

   using namespace std;

对于错误C4430,我认为您在定义功能时忘记voidint,例如

    void myfunction (...)
    {
        //
    }

但在你的代码中你只有

    myfunction()
    {
        //
     }