#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;
};
////////////////////////////////////////////////////////////////////////
#endifC++ 具体和实现分离
最新推荐文章于 2025-06-23 20:08:30 发布
本文详细阐述了如何使用C++实现封装与继承,通过创建Widget类和WidgetImpl类来展示C++面向对象编程的基本概念。文章深入探讨了类的定义、构造函数、析构函数以及成员变量的作用。
1837

被折叠的 条评论
为什么被折叠?



