Overloading operator and variadic arguments

Hello guys,

Here goes my first idea:

1
2
3
4
5
6
7
vector<T> operator[](vector<int> pos){
	vector<T> val(pos.size() );
	for (int i = 0; i < pos.size(); ++i){
		val[i] = _val[ pos[i] ];
	}
	return val;
}


It's nice and functional but I was wondering to do it in this way, using variadic arguments:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
vector<T> operator[](int pos, ...){
	T val;
	vector<T> values;

	va_list vl;
	va_start(vl,pos);
	for (int i=0 ; i<amount ; i++){
		val = va_arg(vl,int);
		values.push_back(val);
	}
	va_end(vl);
	
	return values;
}


That's not compiling.

It's not possible to use variadic arguments overloading an operator, is it?
or am I doing some mistake?

Thank you everyone!
It's not possible: the number of arguments passed to each operator is fixed in the language grammar.

"v[1,2,3]" can never parse into a call to an operator[] that takes three arguments: it parses into two calls to operator, followed by a call to the single-argument operator[]
Topic archived. No new replies allowed.