Open apachano opened 4 years ago
I think trivial default values should be initialized in the header. For example:
class HeaderFile
{
public:
HeaderFile();
~HeaderFile();
private:
bool active = false;
std::size_t status = 0;
math::Vector3 position; // a type like this should default construct to 0.
ComplexDataStructure data; // if this is complex default initialize it in the constructor/cpp file unless it has a simple default constructor.
}
Putting things like bool
s and integers don't gain anything out of being initialized in the constructor unless it's a value that isn't static (like user input or file input, etc...). I personally believe putting these in the header would be helpful since it will keep a usually busy cpp file a bit tidier.
Should default values be initialized as a default in the header, or in the constructor? What are the advantages and disadvantages of each approach?