Codice PHP:
#include <iostream>
using namespace std;
template<class T>
void bubbleSort( T *array, const int size )
{
void swap( T * const, T * const );
for ( int pass = 0; pass < size - 1; pass++ )
for ( int j = 0; j < size - 1; j++ )
if ( array[ j ] > array[ j + 1 ] )
swap( &array[ j ], &array[ j + 1 ] );
}
template <class R>
void swap( R * const element1Ptr, R * const element2Ptr )
{
R hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
double b[ arraySize ] = { 2.1, 6.3, 4.2, 8.7, 10.9, 12.6, 89.4, 68.7, 45.1, 37.2 };
int i;
cout << "Data items in original order\n";
for ( i = 0; i < arraySize; i++ )
cout << a[ i ];
bubbleSort( a, arraySize ); // sort the array
cout << "\nData items in ascending order\n";
for ( i = 0; i < arraySize; i++ )
cout << a[ i ];
cout << "Data items in original order\n";
for ( i = 0; i < arraySize; i++ )
cout << b[ i ];
bubbleSort( b, arraySize ); // sort the array
cout << "\nData items in ascending order\n";
for ( i = 0; i < arraySize; i++ )
cout << b[ i ];
cout << endl;
return 0;
}
C:\DOCUME~1\federico\IMPOST~1\Temp\ccGuaaaa.o: In function `_tf8_IO_FILE':
//c/docume~1/federico/desktop/untitl~1.cpp(.text$bubbleSort__H1Zi_PX01i_v+0x83): undefined reference to `swap(int *, int *)'
//c/docume~1/federico/desktop/untitl~1.cpp(.text$bubbleSort__H1Zd_PX01i_v+0x88): undefined reference to `swap(double *, double *)'
Come mai mi da questo errore in compilazione?