Hey guys!
Sorry for my rather broken english beforehand, I hope no one minds.
My problem is following:
I have coded a class which allows me to resize my arrays which were allocated dynamicly (I'm not sure if I'm translating it right, but I mean something like this:
int* temp = new int[size+b]
Everything works fine, but now I want to make them usable for common operations like
cout << a[3];
while a is the name of the object representing the array. The object contains 3 member variables: int size, int counter(to keep track how much space is left before a resize is needed) and int* list which points to the content of the array.
I made following:
1 2 3 4
|
int operator[](int a)
{
return list[a];
}
|
so cout << a[3]is no problem anymore.
But this is where it gets tough.
I want to make it possible to make following statement:
a[3] = 5;
i want to be able to overwrite the existing entry at number 3 with the value 7.
For this, I need 2 operators.
operator[] and operator=
But I don't know how to combine these two.
1 2 3 4 5 6 7 8 9 10
|
int operator[](int a)
{
overwrite = a;
return list[a];
}
int operator=(int b)
{
list[overwrite] = b;
}
|
But it won't work. I've included overwrite as a member variable, tried to put both into one operator overload. But it doesn't work.
How can i make the command
a[3] = 7;
valid?
Greetings,
Himzo