MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/cpp/comments/lvhvgz/simple_c_initialization_flowchart/gpfa6av/?context=3
r/cpp • u/konanTheBarbar • Mar 01 '21
65 comments sorted by
View all comments
Show parent comments
9
Why that assert fails????
18 u/Bocab Mar 02 '21 Because one is initialized to size of 5 and the other is of size 1 with that 1 element being "5" 3 u/TryingT0Wr1t3 Mar 02 '21 Is there a Length property we can guarantee to always be unidimensional? 9 u/mort96 Mar 02 '21 Yeah, it's called size(). The problem is that std::vector<std::string> v1{5} creates a vector with 5 empty strings, while std::vector<int> v2{5} creates a vector with 1 int with value 5. 2 u/TryingT0Wr1t3 Mar 02 '21 Ah, ok, now I understood, thanks. It's, very confusing.
18
Because one is initialized to size of 5 and the other is of size 1 with that 1 element being "5"
3 u/TryingT0Wr1t3 Mar 02 '21 Is there a Length property we can guarantee to always be unidimensional? 9 u/mort96 Mar 02 '21 Yeah, it's called size(). The problem is that std::vector<std::string> v1{5} creates a vector with 5 empty strings, while std::vector<int> v2{5} creates a vector with 1 int with value 5. 2 u/TryingT0Wr1t3 Mar 02 '21 Ah, ok, now I understood, thanks. It's, very confusing.
3
Is there a Length property we can guarantee to always be unidimensional?
9 u/mort96 Mar 02 '21 Yeah, it's called size(). The problem is that std::vector<std::string> v1{5} creates a vector with 5 empty strings, while std::vector<int> v2{5} creates a vector with 1 int with value 5. 2 u/TryingT0Wr1t3 Mar 02 '21 Ah, ok, now I understood, thanks. It's, very confusing.
Yeah, it's called size(). The problem is that std::vector<std::string> v1{5} creates a vector with 5 empty strings, while std::vector<int> v2{5} creates a vector with 1 int with value 5.
size()
std::vector<std::string> v1{5}
std::vector<int> v2{5}
2 u/TryingT0Wr1t3 Mar 02 '21 Ah, ok, now I understood, thanks. It's, very confusing.
2
Ah, ok, now I understood, thanks. It's, very confusing.
9
u/TryingT0Wr1t3 Mar 02 '21
Why that assert fails????