For example if we create our own data types,and went to perform operation on them similar to those which are available for the built in numeric data types,in that case we need to expicity overload the chosen operators so the compiler is awr of what we expect to happen when a paticular operator is applied to objects of specifc class.
For example,if we want to use addition operator"+" with objects the compiler will have to the internet statements alike.It can only do this if we code the machanism ourselves.In effect the "+" operator will have to overload to become member function of the class
The machanism of giving such special meanings to an operators provided by c++ except the Following;
1.Class member access operators(.,*)
2.Scope resolution operator(::)
3. Conditonal operato(?:)
Syntax
return type classname :: operator(Arg list)
{
function body;
}
overloading operators is two types unary operators overloading and binary operaters overloading.
Monday, August 10, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment