Should this constructor use the noexcept keyword?

ChuckieAJ 316 Reputation points
2021-07-29T15:56:59.557+00:00

For example:

CRestoreSettingsDlg::CRestoreSettingsDlg(CWnd* pParent /*=nullptr*/)
    : CResizingDialog(_T("RestoreSettings"), IDD_DIALOG_RESTORE_SETTINGS, pParent)
{

}

Code inspection is telling me I should use noexcept. But how do I know if that is OK?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,903 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 47,956 Reputation points
    2021-07-29T17:01:58.66+00:00

    If the classes from which CRestoreSettingsDlg is derived don't specify noexcept for their constructors then it probably should not either. The docs say ---

    Mark a function as noexcept only if all the functions that it calls, either directly or indirectly, are also noexcept or const.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.