Re: Compiler Warning C4373 about virtual methods

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



"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.

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.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



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, ... where it used to call base class version). ...
    (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)
  • Re: VC++ standard compliance - code
    ... derived class if I add a using declaration in the public section of the ... > object parameter that makes the declarations overloadable. ... >> int NumberOfArguments, ...
    (microsoft.public.vc.language)
  • Re: Unable to match function definition to an existing declaration
    ... >int main ... if you want the base class types to be conveniently available in ... Then you'll be able to use the bare "size_type" in the derived class. ... Thus, at the point of declaration, the ...
    (microsoft.public.vc.language)