c++ - should I use member variable or declare variable inside functions? -
i have class ui handle console i/o c++ program. have 4-5 member functions use variable 'string input' cin input, , of these functions recursive. wondering if should declare 'string input' @ beginning of each of these functions, or if better have private member variable , input.clear() @ beginning of each function. what's best choice, style p-o-v , efficiency p-o-v?
if string input not persistently associated object in long term, , being used locally in short term, make local variable.
1) it's semantically mean anyway.
2) if you're calling recursively, want separate variables per recursive call, local variables give automatically.
3) efficiency standpoint, a) difference small notice anyway, , b) it's faster create new variable on stack keep pointing @ object's member variable, unless construction of expensive.
Comments
Post a Comment