Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QT/mingw-结构中的结构_Qt - Fatal编程技术网

QT/mingw-结构中的结构

QT/mingw-结构中的结构,qt,Qt,我有下面的c程序,它在VisualStudio下编译,但在Qt5.2中失败 #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; } 你知道为什么这

我有下面的c程序,它在VisualStudio下编译,但在Qt5.2中失败

#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;
}

你知道为什么这在Visual Studio中有效而不是在QT中吗?

当我将代码粘贴到一个文件中,并使用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;
}

在Windows上,我必须做同样的更改才能编译它。您确定两种情况下的代码相同吗?可能没有Visual Studio帮助添加的“使用”或其他作用域操作符?

c
编译器还是
c++
编译器?
#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;
}
C:\Users\sarah_000\depot\structs\main.cpp:15: error: C2079: 'ab' uses undefined struct 'main::structB'