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

前端 未结 9 1403
天涯浪人
天涯浪人 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

    Typdefs are definitely are good style. And all your "reasons I like" are good and correct.

    About problems you have with that. Well, forward declaration is not a holy grail. You can simply design your code to avoid multi level dependencies.

    You can move typedef outside the class but Class::ptr is so much prettier then ClassPtr that I don't do this. It is like with namespaces as for me - things stay connected within the scope.

    Sometimes I did

    Trait::ptr
    Trait::collection
    Trait::map
    

    And it can be default for all domain classes and with some specialization for certain ones.

提交回复
热议问题