Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Daishim

Passing n variables?

This topic is 6199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
Also, if all your parameters are the same, you could use an STL vector (or other container) to pass them in.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!