For string types, what's the difference between using push_back and directly concatenating characters with +?

I did a question on leetcode, but for the string type, the push_back concatenation character failed the test, but changed to the plus sign to concatenate the character and passed it.
topic link

my two codes:

class Solution {
public:
    vector<string> generateParenthesis(int n) {
        vector<string> res;
        string part = "";

        __generateParenthesis(res, part, n, n);

        return res;
    }

    void __generateParenthesis(vector<string> &res, string part, int left, int right) {
        if (left == 0 && right == 0) {
            res.push_back(part);
            return ;
        }

        if (left > 0) {
            part.push_back("(");

            __generateParenthesis(res, part, left - 1, right);
        }
        if (right > 0 && left < right) {
            part.push_back(")");
            __generateParenthesis(res, part, left, right - 1);
        }
    }
};

the above is not passable, but the following is passable:

class Solution {
public:
    vector<string> generateParenthesis(int n) {
        vector<string> res;
        string part = "";

        __generateParenthesis(res, part, n, n);

        return res;
    }

    void __generateParenthesis(vector<string> &res, string part, int left, int right) {
        if (left == 0 && right == 0) {
            res.push_back(part);
            return ;
        }

        if (left > 0) {
            // part.push_back("(");

            __generateParenthesis(res, part + "(", left - 1, right);
        }
        if (right > 0 && left < right) {
            // part.push_back(")");
            __generateParenthesis(res, part + ")", left, right - 1);
        }
    }
};

I don"t quite understand. I hope the seniors can give me some guidance.

Mar.03,2021

when you use operator+ , it is sent by value and has not changed part . When push_back () , change part , in the third if , the value of part does not match your expectation. You change the second example to string temp = part; temp.push_back (.); _ generateP. (., temp,.); should also be able to AC.

when PS: is on its own, don't use your own plan. I don't know where you learned it. You must reject it in cPP, because these words are reserved and reserved for standard use. Once you have such a name, it is UB. So when you watch py, it's always very uncomfortable.

Menu