I am attempting to delete the copy constructor using the c++ type system to prevent copying an object.
struct DeleteCopyConstructor {
DeleteCopyConstructor() {};
DeleteCopyConstructor(DeleteCopyConstructor& op2) = delete;
DeleteCopyConstructor(const DeleteCopyConstructor& op2) = delete;
};
DeleteCopyConstructor f() {
DeleteCopyConstructor d;
// initialize d...
return d;
}
The error is:
error: use of deleted function ‘DeleteCopyConstructor::DeleteCopyConstructor(const DeleteCopyConstructor&)’
I've read about copy elision, but it appears to be a compiler optimization, so I don't think it applies. How can I return d
without triggering copy construction?