Internal typedefs in C++ - good style or bad style?

前端 未结 9 1435
天涯浪人
天涯浪人 2020-12-07 07:28

Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e.

class Lorem
{
    typedef boost         


        
9条回答
  •  情话喂你
    2020-12-07 07:54

    Another vote for this being a good idea. I started doing this when writing a simulation that had to be efficient, both in time and space. All of the value types had an Ptr typedef that started out as a boost shared pointer. I then did some profiling and changed some of them to a boost intrusive pointer without having to change any of the code where these objects were used.

    Note that this only works when you know where the classes are going to be used, and that all the uses have the same requirements. I wouldn't use this in library code, for example, because you can't know when writing the library the context in which it will be used.

提交回复
热议问题