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

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

    Currently I'm working on code, that intensively uses these kind of typedefs. So far that is fine.

    But I noticed that there are quite often iterative typedefs, the definitions are split among several classes, and you never really know what type you are dealing with. My task is to summarize the size of some complex data structures hidden behind these typedefs - so I can't rely on existing interfaces. In combination with three to six levels of nested namespaces and then it becomes confusing.

    So before using them, there are some points to be considered

    • Does anyone else need these typedefs? Is the class used a lot by other classes?
    • Do I shorten the usage or hide the class? (In case of hiding you also could think of interfaces.)
    • Are other people working with the code? How do they do it? Will they think it is easier or will they become confused?

提交回复
热议问题