Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function parameters

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I need a function that has four parameters, char, int, float, char. The third parameter has a value of 3.5, and the fourth has a value of 'p'. the function should print the parameters passed to it, one per line. I need to call the function several times, once with two arguments, once with three aguments, and a third time with four.
 
You might declare the function in the header file
like this.


rettype myfunc(char c, int i, float f=3.5, char ch='p');
where ret_type is your functions return type -void, int, float or whatever.

In your function definition,

rettype
myclass::myfunc(char c, int i,float f, char ch)
{
//--- write code here

}

Now you can call the function with 2 ,3 or 4 arguments.
In first case the function takes default value of last 2 arguments, in 2nd case default value of 3rd argument and in last case whatever value you pass to it.

Anand

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top