C++Guns – RoboBlog

30.01.2019

C++ Guns: C++20 Aggregates can no longer declare constructors (schon wieder anders...)

Filed under: Allgemein — Tags: — Thomas @ 21:01

Ab GCC 9.
P1008 Prohibit aggregates with user-declared constructors
Initialization in modern C++ - Timur Doumler - Meeting C++ 2018

Das Thema ist ziemlich lang und eigentlich total überflüssig. Wenn nicht immer die ganzen Altlasten da wären ... but we have to deal with it. Es gibt genügend Artikel im Internet wie gut oder schlecht die Initialisierung in C++ kaputt ist. Für einen guten Überblick, und wie man versucht es zu reparieren, empfehle ich obiges verlinktes PDF.

struct A {
    A() = delete;
};

auto func() {
    // ok does not compile
    // A a; 
    // compiles in c++17 but not in 20
    A a{};      // error: use of deleted function 'A::A()'
}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress