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!

Arguments in function

Status
Not open for further replies.

Arowana

Programmer
Feb 22, 2001
19
0
0
PT
Hi, I know this is a easy question but no one knows everythyng.

In my program i add a c++ file where i create a function.
In that function i want to pass two diferents arguments but one at a time in diferents ocasions.

ex.
CProcura dlg;//modal dialog box class

if(flag==1)

int x=Procura(dlg.m_name);
else
int x=Procura(dlg.m_number);

where m_name is a CString type and m_number is a int type.

The function was declared like: int Procura(void z);

Is that possible and correct?

Thank you in advance!
 
yes, if you do:

int Procura(void z){
char *a;
int b;

if(flag==1){
a = (char *) z;
}else{
b = (int ) z;
}

}

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Excuse me, but the best approach would be defining two OVERLOADED functions:
int Procura(CString s)
{
//...
}

int Procura(int i)
{
//...
}

 
Hi,
What is it (void z)? It is a nonsense.
The code of afe is good. I think, also a good code is
template<class t>int Procura(t argument)
{
.....;
return something;
}
 
My vote is to do like afe suggests and create two overloaded functions that accept the correct datatypes.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top