可以使用什么样的技巧来最小化实现 pImpl 类的工作量?
标题:
class Foo {
struct Impl;
boost::scoped_ptr<Impl> self;
public:
Foo(int arg);
~Foo();
// Public member functions go here
};
执行:
struct Foo::Impl {
Impl(int arg): something(arg) {}
// All data members and private functions go here
};
Foo::Foo(int arg): self(new Impl(arg)) {}
Foo::~Foo() {}
// Foo's public functions go here (and they refer to data as self->something)
您将如何改进这一点,使用 Boost、可能的继承、CRTP 或其他技巧来避免尽可能多的样板代码?运行时性能不是问题。