I am trying to create a bit-vector class in C++ to model some hardware. In most HDLs (hardware description langauges) that I know, specific bits are referenced like this:>
Is there any way to tell
operator[]
to accept two arguments?
No.
There's two common alternatives. One is to overload operator()
instead. You then have to invoke it using the ()
syntax.
The other one is to have operator[]
return a proxy object for which operator[]
is overloaded, too. This can be invoked like multi-dimensional arrays in C, with several [][]
in series.