Possible Duplicate:
How can moved objects be used?
What constitutes a valid state for a “moved from” object in C++11?
When implementing move semantics in C++11, should the moved-from object be left in a safe state, or can it be just left in a "junk" state?
e.g. What is the preferred option to implement move constructor in the following example of a C++11 wrapper to a raw FILE*
resource?
// C++11 wrapper to raw FILE*
class File
{
FILE* m_fp;
public:
// Option #1
File(File&& other)
: m_fp(other.m_fp)
{
// "other" left in a "junk" state
}
// Option #2
File(File&& other)
: m_fp(other.m_fp)
{
// Avoid dangling reference in "other"
other.m_fp = nullptr;
}
...
};