Search code examples
c++qtc++11returnreturn-type

Why lambda returns bool?


I've started learning C++11 and C++14 and i have a question. Why lambda not returns 23?

template<class T>
auto func(T t)
{
    return t;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    auto abc = []()->auto { return func(23); };
    qDebug() << abc; // output: true

    return a.exec();
}

Solution

  • You need to actually execute the lambda:

    qDebug() << abc();
    

    Currently the << overload is converting the type of the lambda to a bool, and outputting that.