我在编译 lambda 函数时遇到了问题:
... (int level = 3) ...
QString str = [level] {QString s;for(int i=0;i++<level;s.append(" "));return s;};
错误内容:
error: conversion from 'GainStatistic::getWidgetAndProps(QObject*, int)::<lambda()>' to non-scalar type 'QString' requested
我试过这个变种:
... (int level = 3) ...
QString str ([level] {QString s;for(int i=0;i++<level;s.append(" "));return s;});
error: no matching function for call to 'QString::QString(GainStatistic::getWidgetAndProps(QObject*, int)::<lambda()>)'
但是函数中的 lambda 表达式只是某种类型的值?是对的吗?因此,QString(lambda-that-returns-QString)
必须调用QString::QString(const QString& ref)
构造函数,这必须工作:
... (int level = 3) ...
QString str([level] {const QString& ref = "123";return ref;}); //leads to the same error
另一种变体:
QString str = [level]->QString {QString s;for(int i=0;i++<level;s.append(" "));return s;};
error: expected token ';' got 'str'
MinGW 4.6.1