C++ 具体和实现分离

#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

你可能感兴趣的:(C++ 具体和实现分离)