Afficher un message
Vieux 17/10/2007, 10h25   #1
Dario Menendez
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Throwing a reference to a temporary object

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;
}

  Réponse avec citation
 
Page generated in 0,05368 seconds with 9 queries