Compiler Warning C4373 about virtual methods
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Feb 2008 05:40:03 -0800
Hello everyone,
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"? Putting function pointer into the vtable of the
related class?
2. const is ignored in derived class?
--------------------
This means the compiler must bind a function reference to the method in
either the base or derived class.
Versions of the compiler prior to Visual C++ 2008 bind the function to the
method in the base class, then issue a warning message. Subsequent versions
of the compiler ignore the const or volatile qualifier, bind the function to
the method in the derived class, then issue warning C4373. This latter
behavior complies with the C++ standard.
--------------------
[Code]
class Base {
public:
virtual int goo (const int input) {return 200;}
};
class Derived : public Base {
public:
virtual int goo (int input) {return 200;} // change const property of
input parameter
};
int main()
{
Derived d;
const int a = 1000;
d.goo (a); // pass const to non-const
return 0;
}
[/Code]
Compile warning message,
1>d:\visual studio
2008\projects\test_overriding1\test_overriding1\main.cpp(8) : warning C4373:
'Derived::goo': virtual function overrides 'Base::goo', previous versions of
the compiler did not override when parameters only differed by const/volatile
qualifiers
1> d:\visual studio
2008\projects\test_overriding1\test_overriding1\main.cpp(3) : see declaration
of 'Base::goo'
regards,
George
.
- Follow-Ups:
- Re: Compiler Warning C4373 about virtual methods
- From: Igor Tandetnik
- Re: Compiler Warning C4373 about virtual methods
- Prev by Date: Re: Liskov substitution principle
- Next by Date: Re: change const property through overloading
- Previous by thread: Cliping a char * string
- Next by thread: Re: Compiler Warning C4373 about virtual methods
- Index(es):
Relevant Pages
|