I am having trouble using a template function for shuffling an array.
I have an array of nodes that I have to shuffle and am putting them into this function:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
|
template <class T> void shuffle( T *arr, int len){
int pos;
T temp;
srand(time(NULL)+clock_t());
for(int i = len-1; i > 0; i--){
temp = arr[i];
pos = rand()%i;
arr[i] = arr[pos];
arr[pos] = temp;
}
}
|
The function is called like this;
|
Source code
|
1
|
<Node>shuffle(nodes[1], 29);
|
So that it shuffles postion 1 to 29. However, the compiler gives me this error:
In function `int main(int, char**)':
error: syntax error before `<' token
There is no error before the '<' token, and when I compile without trying to call the function, it works fine, but when I try to use the function, it cannot compile.
Does anybody know why?
Thanks,
Andy.