Delete, Default and Delegating Constructors

If you using modern C++ in your programing life there are three important concepts in your life to manage methods.

If you compose a class without writing your own constructor (or copy constructor), The compiler creates a method for you to overcome basic structures. Of course, it does nothing but it is really necessary.

The thing about a scenario that you overwrite constructor method but this method takes a parameter, What happens if you did not present a constructor without parameter? Of course, the answer is the cosplayer don’t produce any constructor for you. So the default parameter cames here to help to say the compiler to generate a method for you. On the other hand, the delete keywords tells the compiler not to provide any peace of code for us for the method. Let see it in bellow.

In some cases, you do not prefer to implement all of the version of constructors because another version may overcome that problem. So the way is delegating the method to another.

Keep in mind, delegation works before your codes in the method.

You may also like...

1 Response

  1. 2020-04-03

    […] Delete unused constructors with delete keyword. […]

Leave a Reply

Your email address will not be published. Required fields are marked *