Skip to content

Order of operators #6

Description

@cgeroux

had a great question about the + operator. In that operator I have
Vector temp(size+rhs.size);
//do the copy of lhs and rhs into temp and return it.

Then I have something like

c=a+b;

at the end of the + operator the temp vector should have its destructor called. What happens when we assign the result of a+b to c? Has the memory in temp already been freed? I added some print statements and it turns out, that temp isn't destroyed until after its data is copied over to c, or after the assignment operator completes.

Maybe this would be a good exercise

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions