C++ 具体和实现分离

来源:互联网 发布:java license 编辑:程序博客网 时间:2024/06/10 09:36
#ifndef WIDGET_H_#define WIDGET_H_#include <vector>#include <iostream>using namespace std;class WidgetImpl {public:void DoSomething() { cout << "get it!" << endl; }private:int a,b;std::vector<double> v;};class Widget{public:void DoSomething() { pImpl->DoSomething(); }public:Widget() { pImpl = new WidgetImpl; }~Widget() { delete pImpl; }Widget(const Widget& rhs);Widget& operator= (const Widget& rhs){*pImpl = *(rhs.pImpl);}private:WidgetImpl* pImpl;};////////////////////////////////////////////////////////////////////////#endif