c++ - Why does this code using non-qualified "std::swap" function compile? -


in .cpp file implement bubble_sort algorithm. inside bubble_sort function use swap(a, b). don't specify "using name space std" in cpp file. (actually there no header in .cpp file) still complile program without warning or error. know if want use customary function in bubble_sort function, need @ lease declare function in same file. don't understand why don't need thing swap. below cpp file:

bubble_sort.cpp

template <typename type> void bubble_sort(type* originarray, int lengthofarray) {     int ii=lengthofarray-1;     while(ii>0)     {         (int jj=0;jj<ii;jj++)         {             if (originarray[jj]>originarray[jj+1])                 swap(originarray[jj],originarray[jj+1]);         }         ii--;     } } 

first, test template code (at least msvc), should instantiate it.

moreover, if try code class in std namespace, std::swap() can picked compiler via adl (koenig) lookup.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -