no change for private member ???
howdy, i built a class named LinearList and also declares some methods within, one of those is insert which can insert an element into the list
Code:
class LinearList
{
public:
LinearList(int size=0);
~LinearList();
bool isEmpty() const;
bool isFull() const;
int getLength() const;
T getElement(int pos) const;
int find(T ele) const;
LinearList<T> insert(int pos, T ele);
LinearList<T> remove(int pos);
void trace();
private:
int __maxSize;
int __length;
T* __elements;
};
template <class T>
LinearList<T>::LinearList(int size)
{
__maxSize = size;
__length = 0;
__elements = new T[__maxSize];
}
template <class T>
LinearList<T>::~LinearList()
{
delete []__elements;
}
LinearList<T> LinearList<T>::insert(int pos, T ele)
{
if (!isFull())
{
for (int i=__length-1; i>=pos; i--)
{
__elements[i+1] = __elements[i];
}
__elements[pos] = ele;
__length++;
}
return *this;
}
all seems fine but after inserting by code like this:
nothing changed with private member __elements, as if insert action didnt make any effect on it, what's wrong ???