Compiler Warning (level 1) C4301 

Error Message

' derivedclass::function': overriding virtual function only differs from 'baselcass::function' by const/volatile qualifier

The qualifiers in the parameter lists for the functions in the base and derived classes differ. The compiler implements the function declaration in the derived class. To fix this warning, be sure the qualifiers match.

Example

The following sample generates C4301.

// C4301.cpp
// compile with: /W1
// processor: x86 IPF
#include <stdio.h>

class Base {
public:
   virtual void Func(const int i) {
      printf_s("base\n");
    }
};

class Derived : public Base {
public:
   // Delete the following line to resolve.
   void Func(int i) { printf_s("derived\n"); }   // C4301

   // Uncomment the following line to resolve.
   // void Func(const int i) { printf_s("derived\n"); }
};

int main() {
   Base B;
   Derived D;

   B.Func(0);
   D.Func(0);
}