The biggest problem I have with C++ is that it’s waaay too easy to think that you’re a “C++ programmer” without really understanding all the things you need to understand to use C++ acceptably well.
You’ve got to know RAII,and know to use namespaces,and understand proper exception handling (for example,you should be able to explain why the pop() methods in the STL do not return the values they remove). You’ve got to know which of the three generations of functions in the standard library is the right one. You should be familiar with concepts like PIMPL. You need to understand how the design of the standard library (especially the STL) works. You need to understand how macros interact with namespaces,and why you usually shouldn’t use macros in C++,and what you should use instead (usually templates or inlines,rarely a class). You need to know about boost.
我想我是他提到的那些无耻的C程序员之一.为了保持这个简短,我的问题是
>你能给出一个典型的RAII监管错误的例子,例如哪里的最佳实践决定使用RAII,但程序员已经采用其他方法?
>为什么STL中的pop()方法不返回它们删除的值?
>我读了PIMPL的维基百科条目,不了解它.你可以举一个典型的PIMPL成语用法的例子.
解决方法
> Pop为了速度而返回void: SGI FAQ,并防止对象复制构造函数抛出的异常.
> PIMPL被Qt框架大量使用以提供二进制兼容性.它允许您从公共API隐藏数据结构的所有内部.这意味着,如果要将私有成员添加到类中,则将其添加到d指针.这维护着 Binary Code Compatibility,因为唯一的暴露的数据成员是一个指针.