How do you use "..."?
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).
This is called variable numbers of arguments or varargs. This might help: http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html
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.
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.
Quote:Original post by PumpkinPiemanQuote: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.
Alright, well. Is there some type of method besides this that will allow me to send parameters of an unknown amount?
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement