Hello everyone,
The following code will result in C4373 warning message. In MSDN,
http://msdn2.microsoft.com/en-us/library/bb384874.aspx
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.
--------------------
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
The following code will result in C4373 warning message. In MSDN,
http://msdn2.microsoft.com/en-us/library/bb384874.aspx
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;
}
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