Help swapping array of objects

hi guys i have a problem with swapping two index in class array
the compiler says the following error

Error 14 error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const ExtPerson' (or there is no acceptable conversion)

the = operator here:
(AddressPerson[i] = AddressPerson[i+1];
AddressPerson[i+1] = temextp;)

and this is my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void AddressBook::SortByLastName() const
{
	bool is_swap=false;
	ExtPerson temextp;

	
	for( int pass=1; pass<=noOfPersons; pass++)
	{
		for(int i=0; i<noOfPersons-pass; i++)
			if(AddressPerson[i].getLastn() > AddressPerson[i+1].getLastn())
			{
				
				temextp = AddressPerson[i];
				AddressPerson[i] = AddressPerson[i+1];
				AddressPerson[i+1] = temextp;
				is_swap=true;
			}

			//check if swap happen:
			if(!is_swap)
			{break;}
			is_swap=false;
	}

}


please help me
Last edited on
One would experience similar error in this:
1
2
3
const int foo = 42;
const int bar = 7;
foo = bar; // error, cannot change the value of foo, which is const 

Your array is const. Elements in it are const.

Why? Because you AddressBook is const in this function.

Why? On line 1 you promise that SortByLastName() can be used with const AddressBooks.
ok thanks,
But how i can do swap know!!!
void AddressBook::SortByLastName() const
Presuming that you do understand the meaning of const in the above, why this particular function has const there?
i get what you mean thxxxxxx
Topic archived. No new replies allowed.