Why is operator [] a non-stationary member function?

The C ++ standard states that "=", "()", "[]" must be a non-stationary member function.

Why is this indicated in this way? Why do we need to define a standard this way?

+8
c ++
source share
1 answer

I do not know what the standards committee was thinking, but these operators are not very useful if they do not work on the object itself.

You also have problems if you can use "all" for operator() or operator[] , since they are also used in regular code. If you do not need an object to work with [and, therefore, choosing the right operator through], it becomes messy to figure out which operator[] use.

operator= even more so: what do you assign if not an object? It makes no sense to do this on anything other than an object.

+1
source share

All Articles