C++ Insights - Episode 42: C++20: When is a struct an aggregate

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 4

  • @fh791
    @fh791 Рік тому

    The aggregate also disappears in C++17 when one of the constructors (or both) is explicit :).
    The following code fails to compile.
    struct Point {
    int x;
    double y;
    explicit Point(const Point&) = delete;
    explicit Point(Point&&) = delete;
    };
    const auto pt = Point{2,3};

    • @masheroz
      @masheroz Рік тому

      Did you mean to delete the move constructor?

    • @fh791
      @fh791 Рік тому

      I mean making the deleted constructors explicit

    • @andreas_fertig
      @andreas_fertig  Рік тому +1

      Interesting. I can imagine that the reason is that with the explicit, something other than the default definition of the special member functions get deleted. Maybe that makes the difference here.