By writing a constructor template you can cover several alternatives of the constructors.

But there is also a way to call copy constructor or move constructor when you forwarding an object.

In flowing code, we provided a Has-A type class to understand what type of constructor called.

In the Has-A class, we implemented 4 types of initialization 2 for copy and 2 for the move. You may mention that std::mode has been used to forward parameter without creating a copy of it.

Template method have been used on the MyClass Class and it uses std:: forward method.

std::forward is a template method which looks the type of typetypes. If the type of the template is a reference type, it creates a copy of the object, otherwise moves the object.

1 thought on “Perfect Forwarding with Template”

Leave a Reply

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