Use unnamed object to invoke method or not?
Posted
by
Chen OT
on Programmers
See other posts from Programmers
or by Chen OT
Published on 2014-05-26T14:42:34Z
Indexed on
2014/05/26
22:00 UTC
Read the original article
Hit count: 258
If I have a class with only only public method. When I use this class, is it good to use unnamed object to invoke its method?
normal:
TaxFileParser tax_parser(tax_file_name);
auto content = tax_parser.get_content();
or unnamed object version:
auto content = TaxFileParser(tax_file_name).get_content();
Because I've told that we should avoid temporary as possible. If tax_parser
object is used only once, can I call it a temporary and try to eliminate it?
Any suggestion will be helpful.
© Programmers or respective owner