2014-02-27 72 views
0

中的结构我有下面的C程序,在Visual Studio下编译但在QT 5.2中失败。QT/mingw - struct struct

#include <stdio.h> 

struct structA 
{ 
    int x; 
    struct structB 
    { 
     int d; 
    } y; 
}; 

int main(int argc, char *argv[]) 
{ 
    struct structA ad; 
    struct structB ab; 
    return 0; 
} 

我在QT得到的错误是

error: aggregate 'structB ab' has incomplete type and cannot be definedstruct structB ab; 

任何想法,为什么这个工程在Visual Studio中,而不是QT?

+0

是'c'编译器还是'C++'编译器? – UmNyobe

回答

1

当我将你的代码粘贴到一个文件中,并使用GCC(与MinGW差不多相同的工具链)在Mac上编译它时,我得到了你报告的错误。我可以使误差通过改变这样的代码消失:

#include <stdio.h> 

struct structA 
{ 
    int x; 
    struct structB 
    { 
     int d; 
    } y; 
}; 

int main(int argc, char *argv[]) 
{ 
    struct structA ad; 
    // Tell the compiler where to find structB 
    struct structA::structB ab; 
    return 0; 
} 

错误信息是正确的,我指的structB类型不正确声明,它也需要确定范围以使其可见。

我不知道它是如何能够在Visual Studio下编译的。我试图粘贴相同的代码到Windows上的文件,并与2012 MSVC编译它,我得到这个错误:

C:\Users\sarah_000\depot\structs\main.cpp:15: error: C2079: 'ab' uses undefined struct 'main::structB' 

在Windows上,我不得不做出同样的变化来获得它来编译。你确定代码在两种情况下都是相同的吗? Visual Studio没有帮助添加“使用”或其他范围界定运算符?