auto Function(char dat[]) {
return [&]() {cout << dat << " <- char*\n"; };
}
auto FunctionSub(string dat) {
return [&]() {cout << dat << " <- string\n"; };
}
int main() {
auto f = Function((char*)"HI1");
auto f_sub = FunctionSub(string("HI2"));
f();
f_sub();
return 0;
}
The two functions Function and FunctionSub return similar lambda functions. However, the different thing is only the type of parameter (string and char*).
I thought both HI1 and HI2 will be printed. But when I execute it, HI1 is printed successfully, and HI2 is not printed.
I don't know why HI2 is not printed.