wrote:
> I am trying to sort a 2-dim array of students lastnames. I keep
> getting errors that I cannot assign arrays.
Well, you really need to turn your attention to 'std::string' and
stop using arrays of char to represent strings.
>
> void bubbleSort (char Lstname[][10], int n)
> {
>
> bool swapped = true;
>
> while(swapped){
> swapped = false;
>
> for (int i = 0; i < 40 - 1 ; ++i)
> if (Lstname[i] > Lstname[i+1]) {
>
> swap(Lstname[i], Lstname[i+1]);
You're trying to swap arrays here. The default implementation of
'swap' simply tries to assign the values. You need to provide your
own (custom) implementation (specialisation) of 'swap', something
like
template<class T, size_t s>
void swap(T (&a1)[s], T (&a2)[s])
{
for (size_t i = 0; i < s; ++i)
swap(a1[i], a2[i]);
}
and place it outside your 'bubbleSort'
> swapped = true;
> }
> }
> }
> I get these error messages on compilation:
>
> C:\Documents and Settings\Admin\My
> Documents\C++\assignments\prog5.cpp:215: instantiated from here
> C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:130: error: invalid
> initializer
> C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:131: error: ISO C++
> forbids assignment of arrays
> C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:132: error: ISO C++
> forbids assignment of arrays
>
> Execution terminated
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask