c++ - 匿名结构作为返回类型

标签 c++ visual-c++ struct return-type function-declaration

以下代码compiles fine with vc++ 19.00.23506 (标志:/Wall/WX/Za)和 vc++ 19.10.25109.0(标志:/Wall/WX/Za/permissive-,这可以在 http://webcompiler.cloudapp.net 中检查),但是 doesn't compile with clang 3.8.0 and g++ 6.3.0 (标志:-std=c++11 -Wall -Wextra -Werror -pedantic-errors)。它是 vc++ 中的错误吗?标准是否禁止此类构造?

struct
{
}
foo()
{
    return {};
}

int main()
{
}

最佳答案

MSVC 出现错误:

[dcl.fct]/9 Types shall not be defined in return or parameter types...

关于c++ - 匿名结构作为返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42888031/

相关文章:

c - 如何开始使用 MSVC 运行

c# - 如何从 C# 中的 C++/CLI dll 访问类型?

windows - windows下如何像静态库一样发布代码

c - C 中结构体的大小

c++ - 如何使用 Win32 操作现有桌面快捷方式的图标?

c++ - 最大矩阵成本路径,

c# - 从 C++ 应用程序访问 C# 用户设置

c - 如何使用用户输入的结构填充动态数组的元素?

c - 具有灵活成员类型的结构?

c++ - 链表部分