Referring to http://en.wikipedia.org/wiki/Copy_elision
I run the code below:
The output I received is:
Gaurav@Gaurav-PC /cygdrive/d/Trial $ make clean rm -f Trial.exe Trial.o Gaurav@Gaurav-PC /cygdrive/d/Trial $ make g++ -Wall Trial.cpp -o Trial Gaurav@Gaurav-PC /cygdrive/d/Trial $ ./Trial Hello World! Hello World!
I understand that the compiler could optimize the code with unnecessary copying, which it does not do here.
But what I want to ask is: how are two calls to the copy constructor executed?
catch(C c) - As we pass by value, therefore the copy constructor is called here.
But in throw c how is the copy constructor called? Can someone explain?
c ++
Gaurav k
source share