I am re-learning c++ through the c++ primer book. The author consistently uses declarations like
list::const_iterator result =
find(lst.begin(), lst.end(), search_value);
size_type size=c.count();
Why is he doing that? Why can't we just declare int or float
AlanPosted Apr 21, 2008, 11:14 AM
There's a tendency in C++ to give everything a special type name which is generally a typedef for some predefined type (such as int, float, double etc).
This is done extensively in Windows programming where you have numerous typedefs all meaning, essentially, the same thing.
The only good reason for doing this, IMO, is if the underlying type changes depending on what platform your application is running on which may be the case with a size_type.
However, it's something I've never much cared for (the language is hard enough without having to remember numerous typedefs!) and it's one reason why I prefer to do most of my programming nowadays in C#.