Problem with operator=

This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void deleteEntry (Entry* fpBuffer, int &elemCount) {
int deleteOption;
cout<<"Which entry would you like to delete? (press 0 for main menu)"<<endl;
cin>>deleteOption;
while (deleteOption>elemCount || deleteOption<0) {
cout<<"This entry does not exist!"<<endl;
cin>>deleteOption;
}
if (deleteOption==0)
return;
for (int i=deleteOption; i<=elemCount; i++ ) {
//fpBuffer[i].nameFirst=fpBuffer[i-1].nameFirst;
//fpBuffer[i].nameLast=fpBuffer[i-1].nameLast;
//fpBuffer[i].phoneNumber=fpBuffer[i-1].phoneNumber;
//fpBuffer[i].eMail=fpBuffer[i-1].eMail;
}
elemCount--;
return;
}

Here, fpBuffer is a dynamically allocated array which holds the elements of the structure Entry and elemCount is the number of non empty elements in the structure. I get an error on the commented lines though, "Invalid array assignment". As you can see this is a function which lets the user delete an entry from the book. I am trying to do this by copying every element after the one, specified by the user for deletion, in place of the previous one and then reduce the element count by 1. My question is, do I need to overload the operator=, if yes, how can I do it?
First of all, please indent your code. That means: add spaces, tabs, newlines, so that it's easier to read.
http://en.wikipedia.org/wiki/Indent_style

Secondly, one mostly overloads the assignment operator= when working with classes. Do you? Or do you use a C-style struct instead?

Thirdly, your second return; is not needed.

With that out of the way, you cannot assign arrays like that. That's because they're not first-class citizens. So instead of char[] you may want to use std::string, for which assignment will work as expected.

http://www.cplusplus.com/reference/string/string/operator=/
http://en.wikipedia.org/wiki/First-class_citizen
Topic archived. No new replies allowed.