Skip to content

鸭子类型与 C++20 concept 中 自带干粮 部分的疑问 #79

Open
@muyuuuu

Description

@muyuuuu
#include <concepts>
#include <iostream>
#include <type_traits>

class Data {
public:
    Data(int x, int y) : x{x}, y{y} {}
    int x;
    int y;
    void show() {
        std::cerr << x << " " << y << "\n";
    }
};

不行:

const bool a = requires (Data d{1, 2}) {d.show();};

行:

const bool a = requires (Data d = Data{1, 2}) {d.show();};

是为什么

Metadata

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