By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,671 Members | 1,670 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,671 IT Pros & Developers. It's quick & easy.

match using ellipsis

P: 35
heres a sample program
#include<iostream>
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
Dec 10 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 671
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.
Dec 10 '07 #2

P: 35
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



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.
Dec 10 '07 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
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++.
Dec 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.