EDIT: This problem has been solved.
I didn't notice that "swap" identifier had been overloaded in bubblesort(). :blush: The error from g++ was rather cryptic, to say the least. Well, it's been solved. This thread may be closed/deleted/removed if necessary.
So here I am, trying to implement bubblesort (for fun, what else is bubblesort good for ):
Code:
template <classname>
void swap(classname &x, classname &y)
{
classname temp = x;
x = y;
y = temp;
}
template <class iterator>
void bubblesort(iterator start, iterator end)
{
bool swapped = true;
iterator swap;
for(iterator i = end; i != start && swapped; --i)
{
swapped = false;
iterator j = start, k = start;
++k;
for(; k != i; ++j, ++k)
{
if(*k < *j)
{
swap(*j, *k);
swapped = true;
}
}
}
}
int main()
{
int array[10] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
bubblesort(array, array + 10);
}
In GCC it fails to compile:
Code:
In function `void bubblesort(iterator, iterator) [with iterator = int*]':
`swap' cannot be used as a function
Even when I specialize the functions to int types and int* iterators, it outputs more or less the same thing.
When I remove swap() completely, gcc again produces the same error "`swap' cannot be used as a function".
If you want it, here's is my build line:
Code:
g++.exe "test.cpp" -o "test.exe"
-W -ansi -I"lib\gcc\mingw32\3.4.2\include" -I"include\c++\3.4.2\backward"
-I"include\c++\3.4.2\mingw32" -I"include\c++\3.4.2" -I"include" -L"lib" -s
I'm compiling from Dev-C++ using MinGW 3.4.2, by the way.