visual studio - c++ and the type size_type -
the following code fragment fails compile:
#include <vector> #include <string.h> #include <cstddef.h> #include <stddef.h> using namespace std; vector<int> list1{1,3,5,7,11}; size_type s1 = list1.size();
i using microsoft visual stdio not expect compiler dependent. believe problem failing include correct header. header should including?
bob
size_type
dependent name of container using. need
std::vector<int>::size_type
you use std::size_t
size_type
boils down std::vector<int>::size_type
guaranteed correct.
if using c++11 or higher can forgot detail , use
auto s1 = list1.size();
the compiler deduce correct type , if ever change container type line need changed.
Comments
Post a Comment