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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -