Skip to content

函数返回匿名结构体无法编译 #36

Open
@MrSoul8715

Description

小彭老师好,《现代C++入门:RAII内存管理》一课中提到的:初始化列表妙用,解决函数多返回值,更加fancy的写法无法编译通过。
示例代码:
struct {
    bool b1;
    double d1;
} test_anoy() {
    return {false, 1.0};
}
编译错误:
test.cpp:9:1: error: new types may not be defined in a return type
9 | struct {
| ^~~~~~
test.cpp:9:1: note: (perhaps a semicolon is missing after the definition of ‘’)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions