Is it required to define the initialization list in a header file?

Initialization list is part of constructor’s definition so you need to define it at the same place you define constructor’s body.
This means that you can have it either in your header file:

public:
    Square(int row, int col): m_row(row), m_col(col) {};

or in .cpp file:

Square::Square(int row, int col) : m_row(row), m_col(col) 
{
    // ...
}

but when you have definition in .cpp file, then in header file, there should be only its declaration:

public:
    Square(int row, int col);

Leave a Comment