Given:
class example
{
public:
std::vector<std::vector<int>> a;
int b;
}
func()
{
example e;
... // populate e
I could then use examples members like so.
int n = e.b;
int n2 = e.a[2][3];
However, could I alternatively override the [ ] operator such that.
int n = e.b;
int n2 = e[2][3];
}
?
edit: Sorry, the example is now fixed.
What you could do is overload the access operator and delegate it to the vector:
The first
[]will then return a reference toa‘s respective element, on which the second[]will be used.