1
void setCurrentTransformations(const NodeTransformations& theSet){
    m_currentTransformations=theSet;
}

I want to confirm that I am understanding this exactly because theSet is going out of scope just after this function gets called.

This is going to actually copy theSet into m_currentTransformations, right? In other words, it is safe, regardless of the scope of theSet in the caller.

It's the fact that if this was a pointer instead of a reference, I know it would not be safe. But I assume here that it is perfectly fine, and m_currentTransformations will copy theSet so that it will not matter what happens to the original value that theSet references, right?

johnbakers
  • 24,158
  • 24
  • 130
  • 258

1 Answers1

4

This is going to actually copy theSet into m_currentTransformations, right?

Absolutely, this is going to make a copy. However, it is going to do so using the assignment operator of the NodeTransformations class, so you may need to be careful of how it is defined. If you define a copy constructor, you usually need an assignment operator and a destructor, too (that is commonly known as the rule of three).

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • "Need" is a little strong. I have several classes that need copy constructors and assignment but don't need destructors. – Ryan Witmer Apr 24 '13 at 18:49
  • @RyanWitmer You're right, there are [exceptions to the rule of three](http://stackoverflow.com/q/15557406/335858), so I should have said "usually need" instead of just "need". Thanks! – Sergey Kalinichenko Apr 24 '13 at 18:59