Please please help me out? My program won't compile.. I'm so confused

I had an assignment from my professor in which I have to build up the code and make it work. I have finished my code and it won't compile, reason being that when I tried to get the value of something, it's not included in the class.. I'm wondering where I went wrong? Can someone help me out please, I'm a beginner in C++ and i've been trying to figure this out for 3 hours but to no avail.. Any help would be great thank you..


#include <iostream>
#include <cstdlib>
#include <string>
using std::cout;
using std::endl;
using std::string;
using std::ostream;

void Assert (bool val, string s) {
if (!val) {
cout << "Assertion failed: " << s <<endl;
exit (-1);
}
}

template <typename E> class List {

private:
void operator = (const List&) {}
List (const List&) {}
public:
List() {}
virtual ~List() {}

virtual void clear() = 0;

virtual void insert(const E& item) = 0;

virtual E remove() = 0;

virtual void moveToStart() = 0;

virtual void moveToEnd() = 0;

virtual void prev() = 0;

virtual void next() = 0;

virtual int length() const = 0;

virtual int currPos() const = 0;

virtual void moveToPos(int pos) = 0;

virtual const E& getValue() const = 0;
};

template <typename E>
class AList : public List<E> {
private:
int MaxSize;
int listsize;
int curr;
E* listArray;
const static int defaultsize= 100;

public:
AList(int size=defaultsize) {
maxSize = size;
listSize = curr = 0;
listArray = new E[maxSize];
}

void Alist() { delete [] listArray; }

void clear() {
delete [] listArray;
listSize = curr = 0;
listArray = new E[maxsize];
}

void insert(const E& it) {
Assert(listSize < maxSize, "List capacity exceeded");
for (int i=listSize; i>curr; i--)
listArray[i] = listArray[i-1];
listArray[curr] = it;
listSize++;
}

E remove() {
Assert((curr>=0) && (curr<listSize), "No Element");
E it = listArray[curr];
for(int i=curr; i<listSize-1; i++)
listArray[i] = listArray[i+1];
listSize--;
return it;
}
void moveToStart() {curr = 0;}
void moveToEnd() {curr=listSize;}
void prev() {if (curr != 0) curr--;}
void next() {if (curr < listsize) curr++;}

int length() const {return listsize;}
int currPos() const {return curr;}
void moveToPos(int pos) {
Assert ((pos>=0) && (pos<=listSize), "pos out of range");
curr = pos;
}

const E& getValue() const {
Assert(( curr>=0) && (curr<listSize), "No current element");
return listArray[curr];
}
};

int main(int argc, char** argv) {

cout << "This is my program" << endl;

AList<int> MyList;

MyList.insert(1);
MyList.insert(2);
MyList.insert(3);
MyList.insert(4);

int x;
MyList.moveToStart();
x = MyList.getValue();
cout << x << endl;

MyList.next();
x = MyList.getValue();
cout << x << endl;

MyList.next();
x= MyList.getvalue();
cout << x << endl;

MyList.next();
x= MyList.getvalue();
cout << x << endl;

system("pause");

return 0;
}
1. Edit your post: Remove all the code, then copy and paste it again within code tags. Code tags are explained here: http://cplusplus.com/articles/z13hAqkS/ . This is so we can see formatted code which is far easier to read. It also numbers the lines so we can refer to specific lines easily.
2. You say you get errors compiling. Always show the errors you are getting. Include the error messages.
Topic archived. No new replies allowed.