non static number of function parameters?

This is a discussion on non static number of function parameters? within the C++ Programming forums, part of the General Programming Boards category; Ive seen some library functions that do it, but lets say... How would you write a max() function that could ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    non static number of function parameters?

    Ive seen some library functions that do it, but lets say...


    How would you write a max() function that could take 2 or more parameters, without rewriting the function for 3 params, 4 params, 5 params, etc..?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    int max (int num_para, ... ) {
    // Stuff to do the compares for each item
    return the_value_of_the_max_item;
    }
    look up va_list for more on how to handle variable number of parameters

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 10:20 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 03:03 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21