I have a class which I have written its [] operator, and I want that sometimes the operator will return an int and sometimes a struct.
But the compiler won't let me overload the operator, why?
It says:"...cannot be overloaded"
Code:
template <class T> struct part { }; template <class T> class LinkedList { public: LinkedList() : size(0), head(0) {} T& operator[](const int &loc); part<T>& operator[](const int &loc); }; template <class T> T& LinkedList<T>::operator[](const int &loc) { ..a lot of thing which compiles perfectly } template <class T> part<T>& LinkedList<T>::operator[](const int &loc) { ...the same thing but returns struct&. }
x[i], how should the compiler chose which operator to call?