By value:

```
class Test {
private:
    HugeObject h; // Copy 1
public:
    void SetObject(HugeObject hugeObject) { // Copy 2
        h = hugeObject;                     // Copy 3
    }
}

// Somewhere else
Test t();
t.SetObject(HugeObject());

```

This is bad because three implicit copies are created. If I change the parameter of `SetObject()` to `const HugeObject& hugeObject`, it's also bad because I'd be storing something that will no longer exist outside that function's scope.

So, to prevent copying twice and storing invalid data, I can copy just twice instead:

```
void SetObject(const HugeObject& hugeObject) { 
    h = HugeObject(hugeObject); // Copy constructor
}

```

Is this a valid way of handling this situation or am I misunderstanding something? A silly optimization or not an optimization at all? Are there better ways, aside from storing a pointer?