match using ellipsis

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • femina
    New Member
    • Dec 2007
    • 35

    #1

    match using ellipsis

    heres a sample program
    #include<iostre am>
    using namespace std;
    void add(...)
    {
    cout<<"match using ellipsis";
    }
    void add(int a,int b)
    {
    cout<<"a and b are"<<a<<b;
    }
    main()
    {
    add(1,2);
    add(1);
    }

    and the op is
    a and b are 1 2(first function call)
    match using ellipsis(secind function call)
    but in the second function definition of match using ellipsis how do i retrieve a and b and use the values of a and b inside my func definition
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    I have to question if you even understand what the implications of the ellipsis are. Functions with ellipsis fall into a category known as variadic functions. This topic is Googleable.

    You have to use the va_arg macros or something. I highly do not recommend pursuing variadic functions. At least not until you have significantly more experience in C++ to understand the pitfalls.

    Comment

    • femina
      New Member
      • Dec 2007
      • 35

      #3
      ya thanks for the answer
      but then that program concept is just to make function overloading and not for the usage of ellipsis thanks for the reply



      Originally posted by oler1s
      I have to question if you even understand what the implications of the ellipsis are. Functions with ellipsis fall into a category known as variadic functions. This topic is Googleable.

      You have to use the va_arg macros or something. I highly do not recommend pursuing variadic functions. At least not until you have significantly more experience in C++ to understand the pitfalls.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by oler1s
        You have to use the va_arg macros or something. I highly do not recommend pursuing variadic functions. At least not until you have significantly more experience in C++ to understand the pitfalls.
        This is really polite. I usually say the only place in C++ where you can use an ellipsis argument is in a catch block. And you never use the va_arg macros unless your are coding in C. That means that functions like printf() and its ilk have no place in C++.

        Comment

        Working...