在 2020/8/11 下午9:55, Nathan Sidwell 写道: > > I agree, it's the way I use auto. I particularly like the > auto *foo = expr; > idiom, when you're getting a pointer, but the type of the pointee is clear. > It informs how you use 'foo'. > >
Personally I dislike this syntax. Pointers are objects, and `auto foo = expr;` should suffice. What if the type of `expr` is `unique_ptr<T>` or `optional<T>`? The ptr-operator just can't exist there. So why the differentiation? `auto& foo = ...` and `const auto& foo = ...` are necessary to indicate that the entity being declared is a reference (and is not an object), while `auto*` doesn't make much sense, as I discourage plain pointers in my projects. -- Best regards, LH_Mouse
signature.asc
Description: OpenPGP digital signature