473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

variable number of function arguments

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

Help
sandX

Jul 23 '05 #1
7 1440
"sandSpiderX" <m7*********@gmail.com> 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.
Jul 23 '05 #2


Tim Love wrote:
"sandSpiderX" <m7*********@gmail.com> 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 23 '05 #3
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?

Jul 23 '05 #4
Ian
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
Jul 23 '05 #5
"sandSpiderX" <m7*********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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)
Jul 23 '05 #6
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.

Jul 23 '05 #7
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...
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Suzanne Vogel | last post by:
'stdarg.h' defines the 'va_arg' type to use in passing variable numbers of parameters to functions. The example of its use given in the Dinkumware documentation *seems* to imply that the 'va_arg'...
7
by: Kapt. Boogschutter | last post by:
I'm trying to create a function that has at least 1 Argument but can also contain any number of Arguments (except 0 because my function would have no meaning for 0 argument). The arguments...
7
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double...
10
by: The Directive | last post by:
I read the C FAQ question on passing a variable number of arguments, but it didn't help. The example assumes all arguments are of the same type. I want to create a function "trace" that can be...
5
by: Sathyaish | last post by:
I knew this but I have forgotten. How do you declare a function that has to accept a variable number of arguments? For instance, the printf() function has a variable number of arguments it can...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
3
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j);...
3
by: carvalho.miguel | last post by:
hello, imagine you have a static class method that receives a function pointer, an int with the number of arguments and a variable number of arguments. in that static method you want to call...
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
2
by: Alan | last post by:
I have a couple of questions about using a variable number of arguments in a function call (...). The context is that I have some mathematical functions I created. I currently pass them a pair of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.