This seems simple to me but I'm having trouble actually finding anything explicitly stating this.
Does std::string stringArray[3]
not create an array of std::string
objects, the way that SomeType typeArray[3]
would? The actual number is irrelevant; I just picked 3 arbitrarily.
In the Visual Studio 2010 debugger, it appears to create a single string as opposed to an array of strings. Why?
Wild guess: is it calling the default std::string
constructor, and then invoking an unused access of index 3? If so, why doesn't that cause an out of bounds exception on an empty string?
Does this have something to do with overloading the []
operator?
There are plenty of ways to code the same things without specifically using an array of std::string
without issue, but what is the explanation/justification for this behavior? It seems counterintuitive to me.
Edit: I found this thread std::string Array Element Access in which the comments on the answer appear to observe the same behavior.