This documentation is archived and is not being maintained.

Compiler Warning (level 1) C4301

Visual Studio .NET 2003

' 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 resolve the warning, be sure the qualifiers match. The following sample generates C4301:

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

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

class Derived : public Base
{
   public:
      void Func(int i) {   // C4301
         printf("derived\n");
      }

      /* use the code below to resolve the warning
      void Func(const int i) {
         printf("derived\n");
      }
      */
};

int main() {
   Base B;
   Derived D;

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