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!
1 Antwort
+ 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?".