Jump to content
  • Advertisement
Sign in to follow this  
PumpkinPieman

How do you use "..."?

This topic is 4495 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

How do you go about creating and using a function with ... as a parameter? What I'm trying to do is achieve a method something a long the lines of scanf() (but different).

Share this post


Link to post
Share on other sites
Advertisement
You don't. Really. Please. Trust me on this. Using the ellipsis construct is a HORRIBLE idea in C++. It was kept around for C compatibility, but it breaks type safety, and means that object destruction may or may not be handled correctly. Learn from how iostreams works.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
You don't. Really. Please. Trust me on this. Using the ellipsis construct is a HORRIBLE idea in C++. It was kept around for C compatibility, but it breaks type safety, and means that object destruction may or may not be handled correctly. Learn from how iostreams works.

What do you mean?

I'm going to be using this to create a method to pass arguements to a script function in C++ using AngelScript.

Share this post


Link to post
Share on other sites
Quote:
Original post by PumpkinPieman
Quote:
Original post by Sneftel
You don't. Really. Please. Trust me on this. Using the ellipsis construct is a HORRIBLE idea in C++. It was kept around for C compatibility, but it breaks type safety, and means that object destruction may or may not be handled correctly. Learn from how iostreams works.

What do you mean?


If you pass in a whole bunch of variables, you have no way of knowing what variable is of what type, and things tend to get messy. A variable of one type might be assumed to be another, which would be a Bad Thing. There are much better ways of acomplishing the same task.

Share this post


Link to post
Share on other sites
Quote:
Original post by PumpkinPieman
Alright, well. Is there some type of method besides this that will allow me to send parameters of an unknown amount?


Operator chaining works, if you don't mind altering the syntax of your calls. Take std::cout << 10 << ' ' << 30; for example. Otherwise you could pass your parameters in a std::vector<boost::any std::vector<boost::variant<int,double,std::string> > or something similar.

Share this post


Link to post
Share on other sites
What do you mean 'you don't use it' ? Use it. It's better than writing a buggy less feature complete version of the exact same thing all by yourself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!