I need to define a copy constructor and an = operator overload for a class. Here's the code:
#include <iostream>
#define MAXITEM 100
using namespace std;
typedef float ItemType;
class List
{
public:
List() {}; // default constrctor
List(const List &x) { /* what to put here */ }; // copy constructor with deep copy
bool IsThere(ItemType item) const {}; // return true or false to indicate if item is in the
// list
void Insert(ItemType item) {}; // if item is not in the list, insert it into the list
void Delete(ItemType item) {}; // delete item from the list
void Print() { // Print all the items in the list on screen
for (int x = 0; x < length; x++)
cout << info[x] << " ";
cout << "\n";
};
int Length() { return length; }; // return the number of items in the list
~List() {}; // destructor: programmer should be responsible to set the value of all the array elements to zero
List & operator = (const List &x) { /* and here */ }; // overloading the equal sign operator
private:
int length;
ItemType info[MAXITEM];
};
I tried just doing something like
info = x.info;
but it just gives me an "expression must be a modifiable lvalue" error.