structure - Is it OK to have a C++ class with lots (lots!) of boolean fields? -
structure - Is it OK to have a C++ class with lots (lots!) of boolean fields? -
i have c++ class lots of bool
fields indicating different aspects of system. class part of class gets copied (a lot!).
my questions:
is ok have class lots of bools? or should manually compact larger info types? given class gets copied lot, there benefit in defining own copy/move constructors? or should leave lone , allow compiler optimize this?
firstly, ok, assuming class not used instantiate huge number of objects. in latter case using whole bool
represent boolean flag might prove wasteful. talking flags represent "different aspects of system", sounds not produce massive amounts of instances.
secondly, maybe should consider converting these fields bool
array indexed enum. example, instead of
bool has_printer; bool needs_optimizations;
use
enum { opt_has_printer, opt_needs_optimization, opt_count_ }; bool options[opt_count_];
this create collection of fields "run-time iteratable", might simplify lot of processing code doesn't care application-specific meaning of each field (like copying code, reading-writing code etc.).
c++ structure intel-c++
Comments
Post a Comment