const int *p vs. int const *p - Is const after the type acceptable?

前端 未结 15 1705
萌比男神i
萌比男神i 2020-12-08 05:01

My co-worker is 0 for 2 on questions he has inspired (1, 2), so I thought I\'d give him a chance to catch up.

Our latest disagreement is over the style issue of wher

15条回答
  •  感动是毒
    2020-12-08 05:27

    In modern C++11, you could also use template typedefs to add clarity to complicated declarations:

    template
    using Const = const T;
    
    template
    using Ptr = T*;
    

    The three declarations you mentioned in your question:

    int const * a;
    int * const b;
    int * const * c;
    

    would then be written as:

    Ptr> a;
    Const> b;
    Ptr>> c;
    

提交回复
热议问题