variable number of function arguments

Discussion in 'C++' started by sandSpiderX, Jul 12, 2005.

  1. sandSpiderX

    sandSpiderX Guest

    Hi,
    How do i declare and use a function in c++ with variable number of
    arguments...

    Help
    sandX
     
    sandSpiderX, Jul 12, 2005
    #1
    1. Advertising

  2. sandSpiderX

    Tim Love Guest

    "sandSpiderX" <> writes:

    >Hi,
    >How do i declare and use a function in c++ with variable number of
    >arguments...

    One way is to read up about "Default Arguments in C++ Functions",
    but that might not solve all your problems.
     
    Tim Love, Jul 12, 2005
    #2
    1. Advertising

  3. sandSpiderX

    Guest

    Tim Love wrote:
    > "sandSpiderX" <> writes:
    >
    > >Hi,
    > >How do i declare and use a function in c++ with variable number of
    > >arguments...

    i dont know any special ways in C++, but varargs are one way to do (in
    C) and i believe its portable too
     
    , Jul 12, 2005
    #3
  4. sandSpiderX

    Son of Sam Guest

    do u mean this:

    int main(int argc, _TCHAR* argv[])
    {
    .....

    or do u want to call a function like this:

    int bum(int x, char g, string pop)
    {
    ....
    bumb(0, "", "only here")
    or woot?
     
    Son of Sam, Jul 12, 2005
    #4
  5. sandSpiderX

    Ian Guest

    sandSpiderX wrote:
    > Hi,
    > How do i declare and use a function in c++ with variable number of
    > arguments...
    >

    Don't, find a better way! This hangover from C looses all of the type
    safety provided by C++

    Ian
     
    Ian, Jul 12, 2005
    #5
  6. "sandSpiderX" <> wrote in message
    news:...
    > Hi,
    > How do i declare and use a function in c++ with variable number of
    > arguments...



    If the arguments have the same type, you could pass the arguments in
    a vector or list or something of that sort. Otherwise, stick to Ian's
    advice.
    --
    jb

    (reply address in rot13, unscramble first)
     
    Jakob Bieling, Jul 12, 2005
    #6
  7. sandSpiderX

    upashu2 Guest

    An another solution is a string. write all parameters to a string,
    like "x=10,name=ashu,y=20.05" and parse this string inside the
    function.
     
    upashu2, Jul 12, 2005
    #7
  8. sandSpiderX

    Ben Pope Guest

    upashu2 wrote:
    > An another solution is a string. write all parameters to a string,
    > like "x=10,name=ashu,y=20.05" and parse this string inside the
    > function.


    Surely a map of strings with your favourite key type would be more flexible, easier, faster, than that?

    Ben
    --
    I'm not just a number. To many, I'm known as a String...
     
    Ben Pope, Jul 12, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    1
    Views:
    384
    Ron Natalie
    Oct 16, 2003
  2. Vince
    Replies:
    3
    Views:
    564
    Victor Bazarov
    Nov 10, 2004
  3. jmborr
    Replies:
    1
    Views:
    459
    Stargaming
    Nov 3, 2007
  4. Replies:
    3
    Views:
    866
  5. Navaneeth
    Replies:
    4
    Views:
    576
    Kenny McCormack
    Nov 20, 2010
Loading...

Share This Page