Can Static Functions Be Virtual in C++? Last Updated : 06 Jun, 2022 Comments Improve Suggest changes 58 Likes Like Report In C++, a static member function of a class cannot be virtual. Virtual functions are invoked when you have a pointer or reference to an instance of a class. Static functions aren't tied to the instance of a class but they are tied to the class. C++ doesn't have pointers-to-class, so there is no scenario in which you could invoke a static function virtually. For example, below program gives compilation error, CPP // CPP Program to demonstrate Virtual member functions // cannot be static #include <iostream> using namespace std; class Test { public: virtual static void fun() {} }; Output prog.cpp:9:29: error: member ‘fun’ cannot be declared both virtual and static virtual static void fun() {} ^ Also, static member function cannot be const and volatile. Following code also fails in compilation, CPP // CPP Program to demonstrate Static member function cannot // be const #include <iostream> using namespace std; class Test { public: static void fun() const {} }; Output prog.cpp:8:23: error: static member function ‘static void Test::fun()’ cannot have cv-qualifier static void fun() const {} ^ Create Quiz Comment K kartik Follow 58 Improve K kartik Follow 58 Improve Article Tags : C++ C++-Static Keyword Static Keyword Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like