using semicolons in user defined functions

closed account (4Gb4jE8b)
can you do it? and if so can you show me an example? something presumably that would look like this:

1
2
3
4
int myfunction(int a; int b; int c)
{
   //do something
}


any help is appreciated!

if you can do it, are there certain limitations like all arguments have to be included?
Last edited on
Argument must be separated by commas, not by semicolons.
What are you trying to do?
closed account (4Gb4jE8b)
I am trying to have multiple sets of information for the same argument. For example

http://pastebin.com/H8ZAMnFZ

will show the full current directory or all the files in the directory of one extension. Instead of using this function multiple times to display types of different extensions, I'd rather have

listdir(".";".txt",".rtf",".doc")

and then change the code to allow for this. However with only commas separating the arguments, I can't think of a way to do this.

The main reason i ask is because in a for loop, the difference in arguments are seen by ';' not ',' and I was hoping this could be done similarly.
Last edited on
Why not send a vector of strings and loop through the vector for the vars?

You can also try http://www.cplusplus.com/reference/clibrary/cstdarg/
Last edited on
Not to mention

1. bitflags

2. Arrays

3. A null terminated list of null terminated strings.

4. stringstream

5. linked lists

Last edited on
closed account (4Gb4jE8b)
Yes i could send an array of strings, or a vector as you suggested, but I was hoping for an easily understood standard for the function, so that i don't have to go back to it in the future to understand the arguments. Thanks for the link, I haven't heard of that before.

But i feel it would be easier if i could just use a semicolon, so that i don't have to pass... well it would basically be a copy of ".txt",".rtf".".doc" in a different form.
Last edited on
Stringstreams provide a similar syntax. You can copy it in a class of your own you can use as argument.
Or you can put in the function some functionality that will parse a more complex string ( eg ".txt|.rtf|.doc" ) dividing each part separated by '|' ( or whatever character you choose ) into different strings
C++0x Will allow something like this: listdir ( ".", {".txt",".rtf",".doc"} )
if the second parameter is a vector or some other sequence container
Last edited on
closed account (4Gb4jE8b)
bazzy, thanks! I didn't think about parsing the data with a unique character (which is ironic, considering the program is for parsing text...) That will work nicely.
Topic archived. No new replies allowed.