Oct 25, 2016 at 5:02pm UTC
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 Oct 25, 2016 at 5:04pm UTC
Oct 26, 2016 at 10:47am UTC
ok thanks,
But how i can do swap know!!!
Oct 26, 2016 at 10:59am UTC
void AddressBook::SortByLastName() const
Presuming that you do understand the meaning of const in the above, why this particular function has const there?
Oct 28, 2016 at 5:58pm UTC
i get what you mean thxxxxxx