On Sat, 19 Jun 2004 21:50:38 +0200, "Kapt. Boogschutter"
<so*****@nobody.com> wrote in comp.lang.c++:
I'm trying to create a function that has at least 1 Argument but can also
contain any number of Arguments (except 0 because my function would have no
meaning for 0 argument).
The arguments passed to the function are strings or must be (automaticly
converted to a string e.g. the number 10 should become the string "10".
My problem is that I can only find samples and description of printf() like
functions where the optional arguments and types are specified within the
first argument.
Since this is not the case with my function I have no idea how to make this
function and make the type conversion as descriped before.
Can anyone point me in the right direction?
ThanX
Let me get this straight. You are trying to write a function that can
accept one or more arguments. These arguments are all strings, and
the first string does not contain information about how many other
strings there might be. Is that correct?
In that case, if I call:
your_function("one");
your_function("one", "two");
your_function("one", "two", "three");
....how are you going to write your function so that when it sees "one"
it knows whether or not there is a "two" or a "three"?
The standard header <cstdarg> provides a mechanism for a function to
access a variable argument list, but there must be a mechanism for it
to determine what the arguments are (how many and what type). If you
don't want the information in the arguments before the variable ones
to tell you, you must use some kind of special end item.
If your function must be called like this:
func("one", (char *)0);
func("one", "two", (char *)0);
func("one", "two", "three", (char *)0);
....with the null pointer indicating the end of the list, you can still
use <cstdarg.h>.
For sure your function must have some way of knowing how many
parameters are passed, because if it tries to go past the number you
get undefined behavior, and probably a crashed program.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html