0

Here is another code analysis warning:

Warning C26435 Function CAssignSelectedColumnDlg::DoDataExchange should specify exactly one of virtual, override, or final (c.128).

Example (boilerplate MFC code):

void CAssignSelectedColumnDlg::DoDataExchange(CDataExchange* pDX)
{
...
...
}

If I understand the documentation correctly, I need to attach either:

  • override or
  • final

... to the function declaration in the header?

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

1 Answers1

1

Yes. The link you posted has another link in it:

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-override

You can trust the authors :)

Editors:

Bjarne Stroustrup
Herb Sutter

For others benefit:

void DoDataExchange(CDataExchange* pDX) final;

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
  • Thank you. In my situation then, I would use the keyword `final` because I would not be deriving a new class from my dialog. That is how I understand this. – Andrew Truckle Oct 18 '21 at 18:38
  • 1
    `final` is the correct keyword in this situation. You'd use `override` if the class is intended to be derived from, except when it is the base class of a class hierarchy, in which case the `virtual` keyword is required. The diagnostic is meant to guard against accidentally hiding a `virtual` class member in a derived class with a non-`virtual` class member of the same signature rather than overriding it. This would be legal code that compiles just fine, producing a program that works most of the time. That makes finding this bug particularly challenging. – IInspectable Oct 19 '21 at 07:30