jeudi 26 novembre 2020

Can't use "{}" inside of "?" [duplicate]

Why can't braces initialization operator be used inside of '?' operator?

Am I missing something?

std::function<bool(int,int)> sortfn()
{
    return {};
}

int main(int argc, char *argv[])
{
    bool b = false;
    //auto fn = sortfn();  // compiles OK
    auto fn = b ? sortfn() : {}; // compilation error: syntax error: '{'

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire