C++ 还提供了 export 关键字允许将模板声明从模板定义中分离出来。不幸的是,支持 export 的编译器非常少,而与 export 打交道的实际经验就更少了。结果是,现在就说 export 在高效 C++ 编程中扮演什么角色还为时尚早。
像 Person 这样的使用 pimpl 惯用法的类经常被称为 Handle 类。为了避免你对这样的类实际上做什么事的好奇心,一种方法是将所有对他们的函数调用都转送给相应的实现类,而使用实现类来做真正的工作。例如,这就是两个 Person 的成员函数可以被如何实现的例子:
#include "Person.h" // we’re implementing the Person class, // so we must #include its class definition
#include "PersonImpl.h" // we must also #include PersonImpl’s class // definition, otherwise we couldn’t call // its member functions; note that // PersonImpl has exactly the same // member functions as Person - their // interfaces are identical