我想使用 lambda 表达式初始化一个类成员(
std::string filePath
)。程序编译没有问题,但没有输出。这里出了什么问题?#include <iostream>
#include <string>
class MyString
{
public:
std::string filePath = [this] ()
{
return oneStr.append(" two");
}();
std::string oneStr;
};
int main()
{
MyString str;
str.oneStr = std::string(" one");
printf("%s", str.oneStr.c_str());
}
filePath
初始化时oneStr
已经被构建了。 - Bill Lynch" one two"
对于oneStr
变量? - 김선달