C++ provides the facility of not only overloading the functions - TopicsExpress



          

C++ provides the facility of not only overloading the functions but also the facility of overloading operators like +,- etc. Normally these operators works only with inbuilt data types eg: int , float , double etc and can not work on user defined data types like Distance which is the combination of two types of data members like feet and inch, like Date which have three types of data members eg: Day, Month and Year or Time which have hours, mins and sec. or Complex number which is the combination of real and imaginary numbers. So we improve the programs by overloading the existing operators to work on user defined data types. Operators like . , :: and .* can not be overloaded. Note : Java does not support Operator Overloading and also the Pointers . Example program in C++ to Overload the existing + Operator to work with user defined data type distance. You can also try to overload -, * and / operators to work with the distance type. #include #include class distance //Defining Class distance { private: int feet,inch; // private int data type members feet and inch public: distance(){} //Constructor void getDist() //Function to read distance. { coutfeet; coutinch; } void showDist() //Function to Show the distance { cout
Posted on: Tue, 05 Nov 2013 16:09:02 +0000

Trending Topics



Recently Viewed Topics




© 2015