Skip to main content

Posts

Showing posts with the label Rules for overloading an operator

Mention rules for overloading an operator. Write a program to convert class type of data into basic type.

 Rules for overloading an operator: The operator being overloaded should have at least one operand of a user-defined data type. Overloaded operators must either be a member function or a friend function of the class. Overloaded operators must follow the same syntax and precedence rules as the built-in operators. Overloaded operators cannot change the number of operands, their types, or their intrinsic meanings. Some operators, such as the conditional and the assignment operators, can be overloaded as member functions and as friend functions, but others, such as the scope resolution operator and the conditional operator, can only be overloaded as member functions. Program to convert class type of data into basic type: #include <iostream> using namespace std; class Distance { private:     int feet;     float inches; public:     Distance() {         feet = 0;         inches = 0.0;     }    ...