It doesn't hurt to have one, but it mostly only makes sense for containers (like std::vector
), as all containers provide this typedef
and a uniform interface for accessing the contained values (begin
/end
, front
/back
), although this has mostly gotten obsolete in C++11 with auto
and decltype
. It's still cleaner to say some_template<typename container::value_type> ...
, though.
That in turn means they can be used interchangeably in generic code (the main reason why things were done that way). If it makes sense for your Point
class to know what types the contained values are, well, have that typedef
. As I said, it doesn't hurt. However, I have a feeling that it doesn't make too much sense for that particular example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…