Solved

C++ overloading functions- VERY URGENT

Posted on 2006-11-27
8
262 Views
Last Modified: 2010-04-16
I'm not really sure about how to overload a function or exactly what that means.  I have to write a program where I have to create a function that accepts two arguments of the same type and computes the arithmetic average.  My instructions say to overload the function to work with three arguments.  I know how to go about writing the program, but I'm not sure exactly how to write the whole overloading part.  Thank you.
0
Comment
Question by:alligarbage
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18017881
Is this homework?
Just write one function with two arguments and one function with three arguments.
0
 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18017894
Overloading means you use (declare,implement) the same function for diferent types like cout does:
int i;
char c;
cout << i;
cout << c;
will print both types and operate nice, and will not convert the char to int, or vice-versa. Overloading means so only loading a function name over.
So declare the function with 3 arguments and use the function once with 2 and with 3 and you will see, it compiles and do what it should.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 18017906
Hi alligarbage,

Simply delcare and define two functions with the same names ... One function would accept two arguments while second would accespt three arguments. Both functions would compute and return average value of the arguments aupplied.

Since this is homework question, we cannot give you code. Give it a shot and if you are still stuck, post back here with code and specific question.

Cheers!
sunnycoder
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 6

Expert Comment

by:_iskywalker_
ID: 18017941
it doesnt work not only for different arguments number, if you use 2 different argument types it work also
0
 

Expert Comment

by:ManasiD
ID: 18018221
The following code snippets include declarations for two different overloaded Avg functions, with the ability to handle 2 and 3 parameters each.
Note: Where T is the data type of the argument and tParam1/2/3 are the arguments.
You can include your actually values and check.
<Code edited by sunnycoder, Page Editor>
0
 

Author Comment

by:alligarbage
ID: 18025064
Administrator- I didn't include any code in my post, so I'm not sure what you would have edited.  
0
 

Expert Comment

by:epernice
ID: 18033498
The Administrator was actually talking to ManasiD
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 97
groovy example issue 10 97
python sqlite question 11 46
Windows Service to Receive TCP Packets 4 147
A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question