D
Dario Menendez
Is it possible to throw a reference to a temporary object?
Will the temporary object be copied one or more times?
See following example:
struct my_exception
{
my_exception(int i) : i_(i) {}
my_exception& ref() {return *this;}
int i_;
}
void f_throws()
{
throw my_exception(3).ref();
}
int main()
{
try {
f_throws();
}
catch(my_exception& e) { return e.i_; }
return 0;
}
Will the temporary object be copied one or more times?
See following example:
struct my_exception
{
my_exception(int i) : i_(i) {}
my_exception& ref() {return *this;}
int i_;
}
void f_throws()
{
throw my_exception(3).ref();
}
int main()
{
try {
f_throws();
}
catch(my_exception& e) { return e.i_; }
return 0;
}