Re-use a moved object

suggest change

You can re-use a moved object:

void consumingFunction(std::vector<int> vec) {
    // Some operations

int main() {
    // initialize vec with 1, 2, 3, 4
    std::vector<int> vec{1, 2, 3, 4};

    // Send the vector by move

    // Here the vec object is in an indeterminate state.
    // Since the object is not destroyed, we can assign it a new content.
    // We will, in this case, assign an empty value to the vector,
    // making it effectively empty
    vec = {};

    // Since the vector as gained a determinate value, we can use it normally.

    // Send the vector by move again.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents