0

Char vector accepting different types

Hi, I have a vector of type "char". I assumed that if I would try to add for example an element of type "string" it would give an error. But what it does is it simply adds the last char of the string. Lets say I would add 'Jaguar' to my vector. It will add the char 'r'. Any clarification? Thanks!

14th Jun 2017, 4:42 AM
swabadzu
1 ответ
+ 1
The string class provides an implicit conversion which returns the last character. It just makes more sense than the first char because you could need it slightly more often. Maybe you can abbreviate some code snippets using the conversion. Somebody must have thought: "Why not?".
9th Aug 2017, 1:20 PM
Timon Paßlick