Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

How to handle variable number of arguments?

Question posted by: Lambda (Guest) on July 3rd, 2008 12:45 PM
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?='s Avatar
=?ISO-8859-1?Q?Dar=EDo_Griffo?=
Guest
n/a Posts
July 3rd, 2008
01:05 PM
#2

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's Avatar
Lambda
Guest
n/a Posts
July 3rd, 2008
01:35 PM
#3

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!

 
Not the answer you were looking for? Post your question . . .
189,876 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors