5 ms·
It's simple: "string" literals in C++ are pointers to characters. std::vector has a constructor which takes a begin and end iterator and creates a vector with c
by GrantMoyer 2y ago
It's simple: "string" literals in C++ are pointers to characters. std::vector has a constructor which takes a begin and end iterator and creates a vector with contents copied from that range. Pointers are iterators in C++, and chars are implicitly convertible to ints, so overload resolution selects the aforementioned constructor. The pointer to "1" and the pointer to "2" don't point into the same object, so trying to iterate from one to the other eventually causes a dereference past the end of "1" which is undefined behavior.
- metadat 2y agoI don't know about simple, haha, but thank you so much for explaining in depth!
- jiggawatts 2y agoThis... this is why I gave up C++ programming and have not looked back.