Using std Namespace

前端 未结 16 970
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:57

There seem to be different views on using \'using\' with respect to the std namespace.

Some say use \' using namespace std\', other say don\'t but rathe

16条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 05:11

    Why not for example

    typedef std::vector ints_t;
    ints_t ints1;
    ....
    ints_t ints2;
    

    instead of the unwieldy

    std::vector ints1;
    ...
    std::vector ints2;
    

    I find that much more readable and its my standard for coding.

    You can even use it to include some semantic information for the reader. For example, consider the function prototypes

    void getHistorgram(std::vector&, std::vector&);
    

    which ones the return value?

    How about instead

    typedef std::vector values_t;
    typedef std::vector histogram_t;
    ...
    void getHistogram(values_t&, histogram_t&); 
    

提交回复
热议问题