Original Post
Say if i had a pointer class which was a reference counter and a dynamic array class, how would i override the ctor in the array class to use the [] operators. Why is it that the array ctor gets called at the line myarray[4]=6; instead of the [] overload ?? and how can i access the [] overload method??
template<class T>
class Pointer
{
private:
T* object;
public:
operator T*()
{
return (object);
}
// other functions here, emitted for ease of reading
};
template<class T>
class Array
{
private:
T* array;
unsigned long arraySize;
public:
Array(unsigned long size)
{
arraySize = size;
array = new T[size];
}
T& operator [](size_t index)
{
return (array[index]);
}
operator T*()
{
return (array);
}
// other functions here, emitted for ease of reading
};
int main()
{
Pointer<Array<int> > myarray;
myarray = new Array<int>(5);
myarray[4] = 6;
return0;
}