This code works on linux.
#include <vector>
#include <iostream>
using namespace std;
int main ()
{
vector<int> v(10, 0);
cout << v[100];
return 0;
}
operator[] is declared with a comment
// element access
/**
* @brief Subscript access to the data contained in the %vector.
* @param __n The index of the element for which data should be
* accessed.
* @return Read/write reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and
* out_of_range lookups are not defined. (For checked lookups
* see at().)
*/
reference
operator[](size_type __n) _GLIBCXX_NOEXCEPT
{ return *(this->_M_impl._M_start + __n); }
But MSVS compiler warns of such subscript-out-of-range cases. Is there any way to mimic it's behavior?