value_type and similar typedefs are useful for writing generic code that can work with any STL container. Eg:
Code:#include <vector> #include <list> #include <iostream> template<typename Container> class Foo { Container m_con; public: Foo(const Container& c) : m_con(c) { } typename Container::value_type GetFirst( ) { return *(m_con.begin( )); } }; int main( ) { std::vector<int> a; a.push_back(20); std::list<float> b; b.push_back(1.234f); Foo<std::vector<int> > c(a); Foo<std::list<float> > d(b); std::cout << c.GetFirst( ) << std::endl; std::cout << d.GetFirst( ) << std::endl; return 0; }




Reply With Quote