Assignement operator changing value of the assigned object
问题 I implemented a class to handle some external functions (e.g of another DLL). This functions gives me an integer I can use as a handle. Here is the important part of my code: MyClass { public: MyClass() { handle = getHandlefromExternalFunction(); } ~MyClass { if(handle>0) freeHandleFromExternalFunction(handle); } MyClass& operator=(MyClass& other) { freeHandleFromExternalFunction(handle); handle = other.handle other.handle = 0; //Is this a bad idea? } private: int handle; } In my main