member function overloading. : member method « Class « C++ Tutorial






#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;


class absolute_value {
public:
 int number(int);
 double number(double);
};
  
int absolute_value::number(int test_data)
{
 int answer;

 answer=abs(test_data);
 return (answer);
}

double absolute_value::number(double test_data)
{
 double answer;

 answer=fabs(test_data);
 return (answer);
}

main( )
{
 absolute_value neg_number;

 cout << "The absolute value is "  << neg_number.number(-583) << endl;
 cout << "The absolute value is "  << neg_number.number(-583.1749) << endl;
 return (0);
}








9.4.member method
9.4.1.Declare a class with method
9.4.2.Implement class member function
9.4.3.The class member access operators . and ->
9.4.4.Overloading class member functions
9.4.5.Default values in member functions
9.4.6.Use class as the member function parameter type
9.4.7.member function overloading.
9.4.8.overloading two class member functions
9.4.9.overloading functions in base and derived classes