Connecting Tech Pros Worldwide Help | Site Map

How to handle variable number of arguments?

Lambda
Guest
 
Posts: n/a
#1: Jul 3 '08
How to define such a function that:

1. Accept variable number of std::string arguments,
can be 1, 2, or 3 arguments.
2. Find the longest common prefix of all these strings and
return the position of the end of the longest prefix?
=?ISO-8859-1?Q?Dar=EDo_Griffo?=
Guest
 
Posts: n/a
#2: Jul 3 '08

re: How to handle variable number of arguments?


int myfunc(const std::string& first=std::string(),const std::string&
second=std::string(),const std::string& third=std::string())
{
int where;
bool match=false;
//do somestuff)
if(!nomatch)
return -1;
return where;
}

Lambda wrote:
Quote:
How to define such a function that:
>
1. Accept variable number of std::string arguments,
can be 1, 2, or 3 arguments.
2. Find the longest common prefix of all these strings and
return the position of the end of the longest prefix?
Lambda
Guest
 
Posts: n/a
#3: Jul 3 '08

re: How to handle variable number of arguments?


On Jul 3, 8:56*pm, Darío Griffo <dario.griffo.lis...@gmail.comwrote:
Quote:
int myfunc(const std::string& first=std::string(),const std::string&
second=std::string(),const std::string& third=std::string())
{
int where;
bool match=false;
//do somestuff)
if(!nomatch)
return -1;
return where;
>
}
Lambda wrote:
Quote:
How to define such a function that:
>
Quote:
1. Accept variable number of std::string arguments,
can be 1, 2, or 3 arguments.
2. Find the longest common prefix of all these strings and
return the position of the end of the longest prefix?
>
>
I've never use default argument that way, thanks!
Closed Thread