You could, in principle, call a destructor this way, if you then use placement new to construct the object back into the now-empty space. Something like this:
Foo& Foo::operator=(Foo&& from) {
void* p = this;
~Foo();
return *(new(p) Foo(std::move(from))); // calls Foo(Foo&&) constructor
}
There are significant limitations to this approach - see e.g. this answer. For example, it would exhibit undefined behavior if Foo
has non-static members of const
-qualified or reference type; or if this operator is actually applied to a base class subobject of a class derived from Foo
. For this and other reasons, this is not commonly done.