In this case, the operator+ is overloaded as a friend function, giving it access to the MyClass instances' private members. A new MyClass instance containing the sum of the value and the constant is returned by the friend function, which accepts a double constant and an instance of MyClass as operands.
Because of the overloaded operator's ability to add a constant (10.1) to an object of MyClass, a new instance (d3) can be created, making the equation d3 = 10.1 + d1 legal. After that, the display function is used to show the outcome.
mainly we are able to add a constant to an object as we declared the overloaded function as a friend function as we know friend function does not belong to any class.