Posts

Showing posts with the label Cpp Programming Theory

Operator Overloading Types and Rules | C++ Programming

Operator Overloading It is the mechanism of giving special meanings to an operator. By overloading operators, we can give additional meanings to operators like +, *, -, <=, >=, etc. which by default are supposed to work only on standard data types like ints, and floats. In general, a = b + c; works only with basic types like ‘int’ and ‘float’, and attempting to apply it when a, b and c are objects of a user-defined class will cause complaints from the compiler. But, using overloading, we can make this statement legal even when a, b and c are user-defined types (objects). Even though the semantics of an operator can be expressed, we cannot change its syntax. When an operator is overloaded, its original meaning is not lost. The grammar rules defined by C++ that govern its use such as the number of operands, precedence, and associatively of the operator remain the same for overloaded operators.  We can overload (give additional meanings to) all the C++ operators except the follo