problem in classes and arrays
i have this code:
Code:
Code:
template <typename T> class Array
{
private:
T *nArr;
int aSize;
public:
Array() { aSize = 0; }
~Array() { delete[] nArr; }
T Element(T nVal)
{
T *tArr = new T[aSize+1];
for(int i=0; i<aSize; i++)
tArr[i] = nArr[i];
tArr[aSize] = nVal;
delete[] nArr;
nArr = tArr;
aSize++;
}
void show()
{
for(int i=0; i<aSize; i++)
cout<<"["<<i<<"] "<<nArr[i]<<"\n";
}
};
void func(Array<char*> *array)
{
char str[4] = "abc";
array->Element(str);
array->show();
}
int main()
{
Array<char*> arr;
func(&arr);
arr.show();
getch();
}
as u can see, i'm creating an object (arr) of type Array<char*> and in the "func()" function i'm trying to assign it a new element ("abc").
then i print the whole array, first in func() and then in main().
when i print it in func(), it prints "abc" like it supposed to, but when i print it in main() it doesn't work properly...
what's the problem?