我想知道从函数返回*this是否安全.这个问题显示了一些你可以做到的方法,我的问题是这个例子:
struct test {
string t;
string b;
public:
test& A(string test) { this->t=test; return *this; }
test& B(string test) { this->b=test; return *this; }
};
int main() {
auto a = test().A("a").B("b").A("new a");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
是否会出现内存泄漏?