Re: Compiler Warning C4373 about virtual methods

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Igor Tandetnik wrote:
"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7DBC281E-1B7F-43E6-AC10-6AA69FFC9ADB@xxxxxxxxxxxxx
The following code will result in C4373 warning message. In MSDN,

[url]http://msdn2.microsoft.com/en-us/library/bb384874.aspx[/url]

I do not quite understand the following statement,

1. What means "bind"?

Figure out which actual function a name refers to.

2. const is ignored in derived class?

Top-level const qualifiers are ignored in a function declaration. E.g.

void f(int n);
void f(const int n);

both declare the exact same function.

Sounds like the fix to a bug I filed.


Earlier versions of MSVC compiler got this wrong, and considered the
above declarations distinct. This was particularly noticeable when one
appeared as a virtual function in a base class, and the other in a
derived class: instead of the latter overriding the former, it hid it.
The version you have does the right thing, and considers the
declaration in the derived class an override of that in the base. The
warning just lets you know that it was different in earlier versions,
in case you are working on legacy code and trying to figure out why
it suddenly changed behavior (started calling derived class version
where it used to call base class version).

The bottom line is, be consistent with top-level const and volatile
qualifiers: either don't use them anywhere, or use them everywhere.
Don't mix and match, that only leads to confusion.

Top-level const is an implementation detail, because it only affects the
body and not the interface. I like keeping the declarations inside the
class body clean and then marking parameters as const in the implementation.


.



Relevant Pages

  • Re: Compiler Warning C4373 about virtual methods
    ... Top-level const qualifiers are ignored in a function declaration. ... derived class: instead of the latter overriding the former, ...
    (microsoft.public.vc.language)
  • base/derived name unhiding but with ctors
    ... When a method in a derived class hides a method with the same ... declaration within the derived class to get around it. ... class that call the appropriate methods in the base class. ... But I suppose it's OK to put constructors of ...
    (comp.lang.cpp)
  • Re: Template Specialization, subclassing and overriding
    ... (the main template function is defined in a base class). ... One way or another you have to prevent the declaration in derived ... from hiding the declaration in baseClass. ... into the derived class with: ...
    (comp.lang.cpp)
  • Re: derived class
    ... You mean the text means if we can not modify the derived class, ... declaration part to make it derived from some base class, ...
    (microsoft.public.vc.language)
  • Re: polymorph object - why doesnt it work???
    ... Look at this declaration of display, ... You will see that the virtual function in the base class is a const one, ... but the function declared in the derived class is not. ...
    (comp.lang.cpp)