| <<< Increment ++ and decrement -- syntax | Index | Conversion by constructor >>> |
It is common to define two operator[ ]s
Allows use on left-hand side, and on const objects:
class MyDoubleArray
{
double& operator[](unsigned int i);
double operator[](unsigned int i) const;
//...
};
void copy( MyDoubleArray& dest, MyDoubleArray const& src )
{
for ( size_t idx = 0; idx < src.size(); ++idx ) {
// Use non-const op[] on left, const op[] on right:
dest[ idx ] = src[ idx ];
}
}
| <<< Increment ++ and decrement -- syntax | Index | Conversion by constructor >>> |