1 year ago

#347951

test-img

Pupper Gump

Why do brackets only use the last number in their parameters?

Edit: This question does not already have an answer, especially when you link the wrong question. I was asking why giving 2 parameters, specifically to a std::vector bracket, only used the last parameter. I did NOT ask why you can't overload brackets with more than one parameter. Please, do you research if you're going to say I haven't done mine.

I was surprised to find that when I put multiple numbers in brackets, they only used the last number to work with:

int main()
{
    std::vector<int> input = { 1,2,3 };
    std::cout << input[1, 2, 3, 1];

    return 0;
}

output:

2

Are the previous numbers being ignored, and can I use them when I overload the brackets?

c++

parameters

brackets

0 Answers

Your Answer

Accepted video resources