#include <iostream>
using namespace std;
class Foo
{
public:
Foo()
{
cout << __PRETTY_FUNCTION__ << endl;
}
Foo(Foo&&)
{
cout << __PRETTY_FUNCTION__ << endl;
}
explicit Foo(const Foo&)
{
cout << __PRETTY_FUNCTION__ << endl;
}
};
int main() {
Foo f;
//Foo f2 = f; //1
Foo f3(f); //2
//錯誤訊息看起來 下面兩種capture的寫法都是跟註解1 一樣的語意? 所以我只要explicit就沒辦法capture by value嗎?
//auto l = [f4 = f3]() {};
//auto l = [f4(f3)]() {};
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjbGFzcyBGb28KewpwdWJsaWM6CiAgRm9vKCkKICB7CiAgICBjb3V0IDw8IF9fUFJFVFRZX0ZVTkNUSU9OX18gPDwgZW5kbDsKICB9CiAgRm9vKEZvbyYmKQogIHsKICAgIGNvdXQgPDwgX19QUkVUVFlfRlVOQ1RJT05fXyA8PCBlbmRsOwogIH0KICBleHBsaWNpdCBGb28oY29uc3QgRm9vJikKICB7CiAgICBjb3V0IDw8IF9fUFJFVFRZX0ZVTkNUSU9OX18gPDwgZW5kbDsKICB9Cgp9OwppbnQgbWFpbigpIHsKCUZvbyBmOwoJLy9Gb28gZjIgPSBmOyAvLzEKCUZvbyBmMyhmKTsgLy8yCgkvL+mMr+iqpOioiuaBr+eci+i1t+S+hiDkuIvpnaLlhannqK5jYXB0dXJl55qE5a+r5rOV6YO95piv6Lef6Ki76KejMSDkuIDmqKPnmoToqp7mhI8/IOaJgOS7peaIkeWPquimgWV4cGxpY2l05bCx5rKS6L6m5rOVY2FwdHVyZSBieSB2YWx1ZeWXjj8KCS8vYXV0byBsID0gW2Y0ID0gZjNdKCkge307CgkvL2F1dG8gbCA9IFtmNChmMyldKCkge307CgkKCXJldHVybiAwOwp9