c++ - C++ 函数签名中 `struct` 的使用定义良好吗?

标签 c++ language-lawyer

这个问题与另一个问题类似,但更具体:

using struct keyword in variable declaration in C++ .

考虑以下程序:

#include <stdio.h>

struct Foo {
    int x;
    int y;
};

Foo getFoo() {
    Foo foo;
    return foo;
}

int main(){
    getFoo();
}

上述程序使用 g++ 编译,但不使用 gcc 编译。

我们可以按如下方式修改程序,使其同时使用 gccg++ 编译:

#include <stdio.h>

struct Foo {
    int x;
    int y;
};

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

int main(){
    getFoo();
}

标准是否保证对 struct 关键字的使用在 C++ 中定义良好

最佳答案

是的。这被称为 elaborated-type-specifier .

关于c++ - C++ 函数签名中 `struct` 的使用定义良好吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51778382/

相关文章:

c++ - std::basic_string 是否正式具有隐式生成的 move 构造函数?

c++ - 可以自由地使用涉及类模板参数推导的函数样式转换表达式吗?

c++ - 如何在cpp和c中不使用cout/printf输出文本?

c++ - 将字节数组转换为十六进制时的空格 std::string C++

c++ - 检查这是否正确

c++ - 是否允许在 Base 的实例上编写 Derived 的实例?

c++ - 如何不丢弃 CDC 路径?

包含指针 vector 的类的 C++ 析构函数

c++ - std::print() 线程安全吗?它是否存在文本交错问题?

c++ - "Nested"带括号的类模板参数推导 : GCC vs. clang