Before you ask, va_list doesn't cut it because arguments are objects (va_list only works for plain data types) and I also don't intend to wait for C++0x.
So, I'm looking for a way to pass a variable number of arguments to a class method. I'd like to pass arguments not in array/vector or anything like that. If anyone has idea(s), do tell!
6 replies to this topic
#1
Posted 09 March 2011 - 12:40 PM
A conclusion is where you got tired of thinking.
#define class struct // All is public.
|
|
|
#2
Posted 09 March 2011 - 01:17 PM
Is there a reason you can't use vectors?
#3
Posted 09 March 2011 - 01:27 PM
You could:
1) Using BlainSch's idea, make a superclass of everything that doesn't do anything and use that for the vector
2) Use pointers to all classes passed instead of passing the classes themselves. Since pointers are primitives, you should be fine.
1) Using BlainSch's idea, make a superclass of everything that doesn't do anything and use that for the vector
2) Use pointers to all classes passed instead of passing the classes themselves. Since pointers are primitives, you should be fine.
sudo rm -rf /
#4
Posted 09 March 2011 - 02:43 PM
you can't do function(int count, ...) ? Haven't tried it myself for some time, but I think I remember doing this before C++0x
#5
Posted 09 March 2011 - 03:24 PM
Smilex said:
you can't do function(int count, ...) ? Haven't tried it myself for some time, but I think I remember doing this before C++0x
sudo rm -rf /
#6
Posted 10 March 2011 - 10:23 AM
@BlaineSch, no reason really, I just think it looks prettier that way. :)
Solved with pointers, thanks. I have another sub question: I'm parsing a text file and some lines may have 3 or 4 (or more, but highly unlikely) integer values. Best method to parse them I can think of is to read whole line, split that line by spaces (values are separated by spaces) and then count elements. Any better ideas?
Solved with pointers, thanks. I have another sub question: I'm parsing a text file and some lines may have 3 or 4 (or more, but highly unlikely) integer values. Best method to parse them I can think of is to read whole line, split that line by spaces (values are separated by spaces) and then count elements. Any better ideas?
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#7
Posted 10 March 2011 - 11:16 AM
Do you need to keep track of what integers are on which lines? If not, you can use fscanf() for C, and an std::ifstream object (include <fstream>) for C++. Both use spaces as delimiters by default. If you do need to keep track of lines, you can read in a line and use strtok() or an std::istringstream object (include <sstream>) to do the job.
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










