samedi 28 avril 2018

=delete for user defined member functions apart from constructor, assignment operator c++11

In C++11, we use "= delete" as not to allow the constructors and operator overloaded member functions to be invoked implicitly while doing some operations(change of dataype/assignment of objects).

class color{
 public:    
 color(){cout<<"color constructed called"<<endl;}
 color(int a){};
 color(float)=delete;
 color& operator = (color &a) = delete;
 virtual void paint() = delete;  //What is the use of delete in this function
 virtual void paints () final {};
};

I have used delete on user defined member function in the above example. It says that we can define the paint() function, hence no other function can call it.

Want to know if there is there is any scenarios in which this type of function declaration(paint) would be useful/recommended.

Aucun commentaire:

Enregistrer un commentaire