What is the meaning of the index operator used in the example in [over.sub] / 1?

[over.sub] / 1

Example:

struct X {
    Z operator[](std::initializer_list<int>);
};
X x;
x[{1,2,3}] = 7; // OK: meaning x.operator[]({1,2,3})
int a[10];
a[{1,2,3}] = 7; // error: built-in subscript operator

What is the Zstatement of the operator []?
What is the likely meaning of the expression x[{1,2,3}] = 7;?

+4
source share
1 answer

What is the Zstatement of the operator []?

This is the return type of the function. It is not used at all in this example, so there is no reason for actually defining it as that I just want to show that the function is returning something. Maybe they should, but it really is not necessary.

What is the likely meaning of the expression x[{1,2,3}] = 7;?

, , , ,

[...] [...]

initializer_list , . N . operator() operator[] initializer_list, .

+4

Source: https://habr.com/ru/post/1696294/


All Articles