I need to create an overloaded cout that will print the contents of an array.
so I can say output << a << endl;
and it will print the contents of the object a... which happens to be an array.
class info:
constructor:
I have one overloaded method... which returns the size of the array
I understand this code, I am simply calling the size method from the program, but i don't know how to pass in the array so that i can print it line by line... simple syntax i am sure... but the whole thing is baffling me... I need to be able to call this on any variation of the class, so it cannot be specific to any one array.
so I can say output << a << endl;
and it will print the contents of the object a... which happens to be an array.
class info:
Code:
class List
{
public:
List();
bool empty(); //returns true of false if empty
void front(); //makes current position at beginning of list
void end(); //makes current position at the end of list
void prev(); //places current position at the previous element in the list
void next(); //places current position at the next element in the list
int getPos(); //returns current position or where you are in the list
int SetPos(int); //places current position in a certain position in the list
void insertBefore(int); //inserts a new element before the current position
void insertAfter(int); //inserts a new element after the current position
int getElement(); //returns the one element that current position is pointing to
int size(); //returns the size of the list(number of elements in the list)
void replace(int); //replace the current element with a new one
void erase(); //deletes the current element
void clear(); //makes the list an empty list
void reverse(); //reverse elements in a list
void swap(List); //swaps all the elements of one list with another list
int getMax(); //return Max Size based on const CAPACITY
void display(); //displays contents of list
private:
int current;
int length;
static const int CAPACITY = 20;
int arrayList[CAPACITY];
int arrayCopy[CAPACITY];
};
constructor:
Code:
List::List()
{
//constructor - initialize array's at position 1
int maxLen=CAPACITY;
length=0;
current=0;
arrayList[length];
arrayCopy[length];
//clean up garbage...
for(int i=0;i<CAPACITY;i++)
{
arrayList[i]=0;
arrayCopy[i]=0;
}
}
Code:
ostream& operator <<(ostream& output, List& out)
{
output << out.size()<< endl;
return output;
}
Comment