mgmol
mgmol copied to clipboard
`nullptr` initialization of pointer member variables in class definition
Currently, mgmol classes do not initialize pointer member variables in their class definitions. For example of MGMol<OrbitalsType>
,
template <class OrbitalsType>
class MGmol : public MGmolInterface
{
private:
std::ostream& os_;
MPI_Comm comm_;
XConGrid* xcongrid_; // <--
OrbitalsType* current_orbitals_; // <--
AOMMprojector* aomm_; // <--
Ions* ions_; // <--
....
This is very error-prone and hard to debug, as they have uninitialized pointers which exhibit unexpected behaviors. This practice should be changed as soon as possible, as below:
template <class OrbitalsType>
class MGmol : public MGmolInterface
{
private:
std::ostream& os_;
MPI_Comm comm_;
XConGrid* xcongrid_ = nullptr;
OrbitalsType* current_orbitals_ = nullptr;
AOMMprojector* aomm_ = nullptr;
Ions* ions_ = nullptr;
....
This is usually the safest and shortest initialization. An alternative is to define them as nullptr
in the constructor (For example, MGmol<OrbitalsType>::MGmol(...)
).