What is the automatically generated move assignment operator for a class Number
that contains only one attribute of type std::shared_ptr<Vertex>
?
#include <iostream>
#include <memory>
class Vertex{
Vertex(Vertex&&)=delete;
Vertex(Vertex const&)=delete;
void operator=(Vertex&&)=delete;
void operator=(Vertex const&)=delete;
private:
const size_t index;
public:
Vertex()/*.index initialization.*/{}
};
class Number{
private:
mutable std::shared_ptr<Vertex> vtx=NULL;
public:
Number(){}
const Number& operator=(const Number& rhs ){
if(vtx==NULL){ vtx=std::shared_ptr<Vertex>( new Vertex() ); }
// ...
return *this;
}
//const Number& operator=(Number&& rhs) = delete; // <-- critical line
const Number& operator+=(const Number& rhs);
};
Number operator+(const Number& a, const Number& b){
Number x;
// ...
return x;
}
const Number& Number::operator+=(const Number& rhs){
return (*this + rhs);
}
int main() {
Number u,v,w;
w = u;
w += v;
return 0;
}
We have been using this code and it yielded the intended behaviour when the critical line is commented out. We had been unaware that the compiler is generating this operator automatically. Now, because we cannot delete it since it is actually being critical for the program to function, we would like to know precisely its code. Can someone state it?
We have tried a couple of implementations ourselves that yield an unintended behaviour. Since the automatically generated one does precisely what we need, we would really like to identify it.