I'm trying to overload operator[]
using a template so it is possible to choose what type is returned. Simplified example:
class A
{
uint8_t buff[10];
public:
template<typename T>
T operator[] (uint var)
{
return (T)buff[var];
}
};
Now I want to be able to do something like this:
abc<uint16_t>[5]; // Clearly not allowed
abc.operator[]<uint16_t>(5); // This works but it's stupid
Question: Is it possible to overload operator [] this way? If not, what is the correct way to achieve it?