Share via

Should this constructor use the noexcept keyword?

ChuckieAJ 391 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?

Developer technologies | C++
Developer technologies | 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.

0 comments No comments

1 answer

Sort by: Most helpful
  1. RLWA32 52,571 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.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

Your answer

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