
15 Mar
2005
15 Mar
'05
4:11 p.m.
Sérgio Vale e Pace wrote:
template < typename T > struct auto_set { T & var; T val; auto_set ( T & var, T val ) :
auto_set(T & var,T val = T()): // allows one to just specify a variable to be auto-set back to its default value also
var ( var ), val ( val ) { }
// IMHO I thing itŽs more often useful to use var own value to be restored later: auto_set(T& var) : var(var), val(var) { }
~ auto_set ( ) { var = val; } };
Good point ! I agree. We then need two constructors, with the one not taking a value resetting the variable back to its initial value.