Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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);
}

Community Additions

ADD
Show:
© 2015 Microsoft