Saturday, 7 July 2018

static furnciton Virtula and const

In C++, a static member function of a class cannot be virtual. For example, below program gives compilation error.
#include
 
using namespace std;   
  
class Test
{
   public:
      // Error: Virtual member functions cannot be static     
      virtual static void fun()  { }
};
Also, static member function cannot be const and volatile. Following code also fails in compilation.
#include
 
using namespace std;   
  
class Test
{
   public:
      // Error: Static member function cannot be const
      static void fun() const { }
};

No comments:

Post a Comment