N
Nick Savoiu
In the code below how can I get x[3] to use the const T& operator[]?
Thanks,
Nick
#include <stdio.h>
template <typename T> class C
{
public:
T lv, rv;
const T& operator[](int p) const { printf("CONST\n"); return rv; }
T& operator[](int p) { printf("NON-CONST\n"); return lv; }
};
int main()
{
C<int> x;
return x[1]=x[3];
}
Thanks,
Nick
#include <stdio.h>
template <typename T> class C
{
public:
T lv, rv;
const T& operator[](int p) const { printf("CONST\n"); return rv; }
T& operator[](int p) { printf("NON-CONST\n"); return lv; }
};
int main()
{
C<int> x;
return x[1]=x[3];
}