|
@@ -0,0 +1,74 @@
|
|
|
+
|
|
|
+#include<iostream>
|
|
|
+#include<cstring>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class Pimpl
|
|
|
+{
|
|
|
+private:
|
|
|
+ struct point;
|
|
|
+ point* data;
|
|
|
+
|
|
|
+public:
|
|
|
+ Pimpl(int _x,int _y);
|
|
|
+ Pimpl(const Pimpl& copy);
|
|
|
+ Pimpl& operator=(const Pimpl& copy);
|
|
|
+
|
|
|
+ ~Pimpl();
|
|
|
+
|
|
|
+ int caculater();
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+struct Pimpl::point
|
|
|
+{
|
|
|
+ int x;
|
|
|
+ int y;
|
|
|
+ point(int _x,int _y):x(_x),y(_y)
|
|
|
+ {}
|
|
|
+ int caculater()
|
|
|
+ {
|
|
|
+ return (x+y)/2;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+Pimpl::Pimpl(int _x,int _y)
|
|
|
+{
|
|
|
+ data=new point(_x,_y);
|
|
|
+}
|
|
|
+
|
|
|
+Pimpl::Pimpl(const Pimpl ©)
|
|
|
+{
|
|
|
+ void* memory=new char[sizeof(point)];
|
|
|
+ std::memcpy(memory,copy.data,sizeof(point));
|
|
|
+ this->data=static_cast<point*>(memory);
|
|
|
+}
|
|
|
+
|
|
|
+Pimpl& Pimpl::operator=(const Pimpl& copy)
|
|
|
+{
|
|
|
+ this->data=copy.data;
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+Pimpl::~Pimpl()
|
|
|
+{
|
|
|
+ delete data;
|
|
|
+}
|
|
|
+
|
|
|
+int Pimpl::caculater()
|
|
|
+{
|
|
|
+ return data->caculater();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int main()
|
|
|
+{
|
|
|
+ Pimpl test(1,2);
|
|
|
+}
|