New to board problems with overloading

This is a discussion on New to board problems with overloading within the C++ Programming forums, part of the General Programming Boards category; Hey whats up everybody. Im new to the board and Im trying to understand this overloading thing but I dont ...

New to board problems with overloading

Hey whats up everybody. Im new to the board and Im trying to understand this overloading thing but I dont have a clue. Anyways I have to write a program that adds 2 rational numbers and I have to overload + - * / . I also have to overload the relational and equality operators. Im not sure what that is. Any help will be appreciated

Sorry man I dont understand that. I need to do something like this. Im not sure what to put inside the function. How can I add 2 rational numbers if I only pass in one. Im not sure but I think you can only pass in one parameter when you overload something. I also have numerator and denominator in my private section.

overloading means using the same function name (or operator symbol) and pass it two different sets of paramenters and still get it to work.

Example:

start with the following function:

void add(int, int);
//add takes two ints and does something with them

void add(int, double);
//now add is overloaded to take one int and one double and will do something with them. the function add is overloaded

void add(double, int);
//yes, it is important which sequence you use parameters as this function is different than the one above to the compiler.

void add(double, double);
//another overloaded version of add

void add(double, float);
//yet another overloaded version of add

need I go further? The compiler can determine which version of add to call based on which set of parameters is passed. Note that polymorphism is a related, but different concept, having to do with object methods wherein methods of the same name perform differently based on the type of the object, not the parameters passed to the function/method.

You can do the same thing (overloading) with operators as operators are just shorthand versions of functions.