C++核心準(zhǔn)則ES.47: 使用nullptr表現(xiàn)空指針,而不是0或NULL?

ES.47: Use?nullptr?rather than?0?or?NULL
而不是ES.47: 使用nullptr表現(xiàn)空指針,而不是0或NULL
Reason(原因)
Readability. Minimize surprises:?nullptr?cannot be confused with an?int.?nullptr?also has a well-specified (very restrictive) type, and thus works in more scenarios where type deduction might do the wrong thing on?NULL?or?0.
可讀性。最小化意外性。nullptr不會混同于整數(shù)。同時nullptr具有良好定義(非常嚴(yán)格的)的類型,很多情況下使用NULL或0會導(dǎo)致類型推斷出錯,但使用nullptr就不會。
Example(示例)
Consider:
考慮以下代碼:
void f(int);
void f(char*);
f(0); // call f(int)
f(nullptr); // call f(char*)Enforcement(實(shí)施建議)
Flag uses of?0?and?NULL?for pointers. The transformation may be helped by simple program transformation.
標(biāo)記使用0或者NULL表現(xiàn)指針的情況。這種變換可以或許可以通過簡單的程序進(jìn)行。
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es47-use-nullptr-rather-than-0-or-null
覺得本文有幫助?請分享給更多人。
關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
