'What does Vector.size() returns exactly? Can we Compare it with an Integer directly? [duplicate]

I have an Int called "ListIndex" to store the value of the index, and a pointer of Vector called "EnqueryList".

So If I tried to compare ListIndex with (*EnqueryList).size() directly, it will give me the wrong result, but if I tried to store the value of (*EnqueryList).size() in another integer "Length" and then compare the value of length and value of ListIndex, the result would be correct, why is that?

    cout<<ListIndex<<":"<<(*Enquery).size()-1<<":"<<(ListIndex<(*Enquery).size()-1)<<"\n";
    cout<<ListIndex<<":"<<length<<":"<<(ListIndex<length)<<"\n";

The Result of the above Couts:

-1:2:0

-1:2:1



Solution 1:[1]

What does Vector.size() returns exactly?

Assuming that you actually mean std::vector::size, it returns the number of elements the vector contains. Same applies to the size member function of all standard containers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eerorika