Teen Programmers Unite  
 

 

Return to forum top

passing arguments to overloaded functions using a for loop

Posted by reinald [send private reply] at September 10, 2002, 09:50:01 PM

I'm trying to pass different variables to an overloaded function(the fact that it's an overloaded function probably is not relevant, anyway) using a for loop. The number of iterations depends on the number picked by the user (1-3).

psuedo code:

for (executes 1, 2, or 3 times depending on what the user picks)
must load to pass1,2, or 3 different values to a function as the user inputs the value(s)
end of loop

............ The called function must then make a calculation based on these three different passed values.
Maybe there is a way to do this using arrays?

Posted by buzgub [send private reply] at September 11, 2002, 12:04:27 AM

I can't fathom what you're actually trying to do here. What is the function's purpose? Does it need to work simultaeneously on all of the numbers inputed, some number derived from those numbers, or just one number at a time?

In general, though, arrays are a fairly good way of storing lists of things.

Posted by gian [send private reply] at September 11, 2002, 12:47:43 AM

I am truely confused at what you are trying to do.

Posted by DragonWolf [send private reply] at September 11, 2002, 07:20:35 AM

I think he wants it that the user can choose how many parameters to pass to the function.
Enters the values
Loads the function with the same number of parameters..

If this is what your trying to do, you'll need to make a switch statement to choose the correct overloaded function depending on the number of parameters chosen.

Posted by buzgub [send private reply] at September 11, 2002, 07:26:38 AM

DragonWolf, that sounds completely wrong. As I understand it, the whole point of an overloaded function is that you can have any number of functions with the same name but different parameter lists, so you might have these c++ function prototypes, duly noting that any program with these particular functions is probably badly designed:

int drawfish(int color, int length);
int drawfish(int length);
int drawfish(char* label);


and you could call drawfish(1, 5) OR drawfish(5) OR drawfish("Buzgub's Fish"), and the compiler would automatically use the correct one.
Posted by DragonWolf [send private reply] at September 11, 2002, 09:00:03 AM

thats what I mean't..
I thought he's asking to get
int myfunction(char* myparam1)
int myfunction(char* myparam1, char* myparam2)
int myfunction(char* myparam1, char* myparam2, char* myparam3)

etc...

Posted by DragonWolf [send private reply] at September 11, 2002, 09:00:32 AM

depending on the number of parameters the users requests to type in..

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.