Click here to Skip to main content
15,905,322 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Working with dynamically created dialog Pin
David Crow8-Jan-08 3:13
David Crow8-Jan-08 3:13 
GeneralRe: Working with dynamically created dialog Pin
Hamid_RT8-Jan-08 18:14
Hamid_RT8-Jan-08 18:14 
Generalunexpected exception handler Pin
George_George8-Jan-08 1:46
George_George8-Jan-08 1:46 
GeneralRe: unexpected exception handler Pin
Matthew Faithfull8-Jan-08 7:27
Matthew Faithfull8-Jan-08 7:27 
GeneralRe: unexpected exception handler Pin
George_George8-Jan-08 16:29
George_George8-Jan-08 16:29 
GeneralRe: unexpected exception handler Pin
Matthew Faithfull8-Jan-08 21:50
Matthew Faithfull8-Jan-08 21:50 
GeneralRe: unexpected exception handler Pin
George_George9-Jan-08 2:29
George_George9-Jan-08 2:29 
Generalusing swap to make assignment operator exception safe Pin
George_George8-Jan-08 1:14
George_George8-Jan-08 1:14 
Hello everyone,


The following swap technique is used to make assignment operator exception safe (means even if there is exception, the current object instance's state is invariant).

It used a temporary object "temp" in this sample, and assignment is made on a to temp ar first. Even if there is exception, the current this object's state is not corrupted.

My question is, the pattern works only if there is no exception thrown by swap function. If there are exception in swap function, the state of current object instance may still be corrupted (swap may invoke the assignment operator of member variables). Is my understanding correct?

class A;
A& A::operator= (const A& a)
{
    A temp;
    temp = a; // exception may be thrown
    swap (*this, temp);
    return *this;
}



thanks in advance,
George
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 2:03
mveCPallini8-Jan-08 2:03 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 2:24
George_George8-Jan-08 2:24 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 2:33
mveCPallini8-Jan-08 2:33 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 2:34
George_George8-Jan-08 2:34 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 3:14
mveCPallini8-Jan-08 3:14 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 3:18
George_George8-Jan-08 3:18 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 3:30
mveCPallini8-Jan-08 3:30 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 3:33
George_George8-Jan-08 3:33 
GeneralYou're welcome Pin
CPallini8-Jan-08 3:36
mveCPallini8-Jan-08 3:36 
GeneralRe: using swap to make assignment operator exception safe Pin
toxcct8-Jan-08 2:03
toxcct8-Jan-08 2:03 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 2:12
mveCPallini8-Jan-08 2:12 
GeneralRe: using swap to make assignment operator exception safe Pin
toxcct8-Jan-08 2:17
toxcct8-Jan-08 2:17 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 2:29
mveCPallini8-Jan-08 2:29 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 3:15
George_George8-Jan-08 3:15 
GeneralRe: using swap to make assignment operator exception safe Pin
CPallini8-Jan-08 3:21
mveCPallini8-Jan-08 3:21 
GeneralRe: using swap to make assignment operator exception safe Pin
George_George8-Jan-08 3:27
George_George8-Jan-08 3:27 
GeneralRe: using swap to make assignment operator exception safe Pin
toxcct8-Jan-08 3:35
toxcct8-Jan-08 3:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.