mizizike
asked on
Question about index operator and "at" function
Hello. I am still working on a vector class and I have run into two problems. One that is of most importance is my index operator. The prototype looks like this:
//Index Operator
T& operator[unsigned int];
The implementation looks like this:
template <typename T>
T& vector<T>::operator[unsign ed int pos]
{
if(pos < THE_ARRAY_CAPACITY)
{
return theDataPtr[pos];
}
else
{
return theDataPtr[(THE_ARRAY_CAPA CITY-1)];
}
}
I get multiple errors with this function, and I do not know why. Most of them are along the lines of: operator expected '[' instead of '[]'. Then, when I try to do my at function, which looks like this:
Returns elements at position pos
T& at(unsigned int);
The implementation is exactly the same as the implementation for that of the index operator function, I get unresolved external operators and one that says vector<T>.at(pos) is a bunch of garbage. I require assistance in this matter and appreciate any insight given to me.
//Index Operator
T& operator[unsigned int];
The implementation looks like this:
template <typename T>
T& vector<T>::operator[unsign
{
if(pos < THE_ARRAY_CAPACITY)
{
return theDataPtr[pos];
}
else
{
return theDataPtr[(THE_ARRAY_CAPA
}
}
I get multiple errors with this function, and I do not know why. Most of them are along the lines of: operator expected '[' instead of '[]'. Then, when I try to do my at function, which looks like this:
Returns elements at position pos
T& at(unsigned int);
The implementation is exactly the same as the implementation for that of the index operator function, I get unresolved external operators and one that says vector<T>.at(pos) is a bunch of garbage. I require assistance in this matter and appreciate any insight given to me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//Index Operator
T& operator[](unsigned int pos);