Results 1 to 3 of 3

Thread: optional parameters

  1. #1
    Frenzied Member
    Join Date
    Mar 00
    Posts
    1,089
    can you use optional parameters in C++, like in VB

    Code:
    Function MyFunc(Optional Pram As Long = 10) As Long
    how would I do that in C++ without overloading, I want to do this for a constructor so I can't call it from overloaded versions, and I have loads of optional params of the same type anyway so It'd make it hard to overload

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 00
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can use the stdarg system. I'm not too sure how it works, but you basically define your function thus:

    Code:
    void myfunc(int arg_a, bool arg_b, ...) {
    
    }
    This means that arg_a and arg_b are compulsory (in the normal way), but other arguments can be added onto the end.

    there is then a set of functions and macros to extract an array of parameters. Take printf for example - if you can get the source code to that you should be fine.



  3. #3
    New Member
    Join Date
    May 00
    Posts
    14
    look up va_arg, va_start or va_end in the help files - MSVC has an example program there to help, I'd imagine *nix would have similar in their man pages.

    Shab.

    Code:
    Print WeekDayName(vbMonday)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •