Passing n variables?
Does C++ have a way to enable a function for n variables to be passed, like VB''s ParamArray?
I know only that which I know, but I do not know what I know.
Yes. This is how printf and similar functions work. They are defined something like:
void func(somevariable, ...);
The "..." is actually what you type and not just me being lazy. Then you can use va_start(), va_end(), and va_arg() to get the extra parameters. Of course, this is actually C. I''m not sure if C++ has it''s own method but since C++ >= C, you can use these functions.
void func(somevariable, ...);
The "..." is actually what you type and not just me being lazy. Then you can use va_start(), va_end(), and va_arg() to get the extra parameters. Of course, this is actually C. I''m not sure if C++ has it''s own method but since C++ >= C, you can use these functions.

C++ can use stdargs/varargs as jaxson described.
Useful for truly variable parameter lists.
For most things though, where there''s some variability to parameters, but not too much, you are better off just using C++''s polymorphism and creating multiple methods, or using methods with parameter defaults.
Useful for truly variable parameter lists.
For most things though, where there''s some variability to parameters, but not too much, you are better off just using C++''s polymorphism and creating multiple methods, or using methods with parameter defaults.
You want to avoid dynamic parameters if you can - it''s messy & slow. Best to pass a pointer to a polymorphic class as gmcbay said above.
Brad
Brad
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement