using predefined classes
| hadi (3) | |||
| hi should anyone please tell me what following line means ? list <int>::size_type i; thanks | |||
| helios (829) | |||
| I think I'll need some context. Where did you see this? | |||
| hadi (3) | |||
| here it is : int main( ) { using namespace std; list <int> c1; list <int>::size_type i; c1.push_back( 1 ); i = c1.size( ); cout << "List length is " << i << "." << endl; c1.push_back( 2 ); i = c1.size( ); cout << "List length is now " << i << "." << endl; } I think I understood what it means it means that since list is a template class the type of list size can differ with different type parameters and type of the size in the class will be int in this case , is that correct ? | |||
| firedraco (657) | ||||
I believe
| ||||
| Zhuge (102) | |||
size_type is just a
typedef of
unsigned int, if I remember correctly. | |||
| Duoas (1458) | |||
| But not necessarily. But that is the general intent. The list class looks something like this very simplified example:
Now the actual type of "size_type" can be modified by changing just one line (line 5). Suppose five years from now the STL is working on my 128-bit computer. The number of items a list can hold are more than unsigned long, so the list will define "size_type" to match:
typedef unsigned tredint size_type;(where "tredint" is our hypothetical 128-bit integer type") And you can always reference that type through an actual type instance:
typedef list <int> ::size_type a_big_unsigned_number;Hope this helps. | |||
| hadi (3) | |||
| thanks a lot now I understand | |||
This topic is archived - New replies not allowed.
