当前位置: 首页 > news >正文

海淀网站建设最新的全国疫情数据

海淀网站建设,最新的全国疫情数据,大连手机自适应网站制作公司,网站策划流程C 中的 Pimpl 惯用法 介绍 Pimpl(Pointer to Implementation)是一种常见的 C 设计模式,用于隐藏类的实现细节,从而减少编译依赖和提高编译速度。本文将通过一个较为复杂的例子,展示如何使用智能指针(如 s…

C++ 中的 Pimpl 惯用法

介绍

Pimpl(Pointer to Implementation)是一种常见的 C++ 设计模式,用于隐藏类的实现细节,从而减少编译依赖和提高编译速度。本文将通过一个较为复杂的例子,展示如何使用智能指针(如 std::unique_ptr)来实现 Pimpl 惯用法。

什么是 Pimpl 惯用法?

Pimpl 是 “Pointer to Implementation” 的缩写,这个模式可以帮助我们:

  • 将接口和实现分离
  • 减少头文件中的依赖
  • 加速编译

基本实现

基本的 Pimpl 实现需要一个前置声明的内部类和一个指向该内部类的指针。在这里,我们使用 std::unique_ptr 来管理这个内部类的实例。

MyClass.h

#include <memory>class MyClassImpl; // 前置声明class MyClass {
public:MyClass();~MyClass();void DoSomething();private:std::unique_ptr<MyClassImpl> pimpl;
};

MyClass.cpp

#include "MyClass.h"class MyClassImpl {
public:void DoSomething() {// 实现细节}
};MyClass::MyClass() : pimpl(std::make_unique<MyClassImpl>()) {}
MyClass::~MyClass() = default;void MyClass::DoSomething() {pimpl->DoSomething();
}

示例

假设我们有一个 Car 类,它有多个组件,如 EngineWheel

Car.h

#include <memory>
class CarImpl;class Car {
public:Car();~Car();void Start();void Stop();private:std::unique_ptr<CarImpl> pimpl;
};

Car.cpp

#include "Car.h"
#include "Engine.h"
#include "Wheel.h"class CarImpl {
public:Engine engine;Wheel wheel[4];void Start() {engine.Start();// 其他逻辑}void Stop() {engine.Stop();// 其他逻辑}
};Car::Car() : pimpl(std::make_unique<CarImpl>()) {}
Car::~Car() = default;void Car::Start() {pimpl->Start();
}void Car::Stop() {pimpl->Stop();
}

在这个例子中,Car 的用户只需要包含 Car.h,而不需要知道 EngineWheel 的存在。这样就降低了编译依赖并提高了编译速度。

总结

通过使用 Pimpl 惯用法和智能指针,我们能更有效地隐藏实现细节,提高编译速度,并使代码更易于维护。


文章转载自:
http://nonmetal.bnpn.cn
http://plata.bnpn.cn
http://hebraist.bnpn.cn
http://nostrum.bnpn.cn
http://narvik.bnpn.cn
http://bronchoconstriction.bnpn.cn
http://handplay.bnpn.cn
http://bespatter.bnpn.cn
http://selenite.bnpn.cn
http://spoutless.bnpn.cn
http://nagual.bnpn.cn
http://kat.bnpn.cn
http://reticent.bnpn.cn
http://spanner.bnpn.cn
http://jingle.bnpn.cn
http://balzac.bnpn.cn
http://readvance.bnpn.cn
http://fatty.bnpn.cn
http://monetarily.bnpn.cn
http://unpeaceful.bnpn.cn
http://fourteen.bnpn.cn
http://walking.bnpn.cn
http://aicpa.bnpn.cn
http://goddamned.bnpn.cn
http://ichthyosis.bnpn.cn
http://positivist.bnpn.cn
http://sile.bnpn.cn
http://immaterial.bnpn.cn
http://enantiotropic.bnpn.cn
http://governmental.bnpn.cn
http://early.bnpn.cn
http://spectrophotometer.bnpn.cn
http://therewith.bnpn.cn
http://emeric.bnpn.cn
http://jestbook.bnpn.cn
http://amandine.bnpn.cn
http://milliliter.bnpn.cn
http://pyro.bnpn.cn
http://inevasible.bnpn.cn
http://ariose.bnpn.cn
http://divinable.bnpn.cn
http://furrow.bnpn.cn
http://affably.bnpn.cn
http://promising.bnpn.cn
http://prophesy.bnpn.cn
http://encyclopedism.bnpn.cn
http://zygoid.bnpn.cn
http://azobenzol.bnpn.cn
http://foveolate.bnpn.cn
http://occidentalize.bnpn.cn
http://divorced.bnpn.cn
http://codistor.bnpn.cn
http://associationism.bnpn.cn
http://lithomarge.bnpn.cn
http://multiflora.bnpn.cn
http://register.bnpn.cn
http://meetinghouse.bnpn.cn
http://likewise.bnpn.cn
http://jeanine.bnpn.cn
http://swordsman.bnpn.cn
http://trackwalker.bnpn.cn
http://metatarsus.bnpn.cn
http://desert.bnpn.cn
http://horny.bnpn.cn
http://hydroskimmer.bnpn.cn
http://audiogenic.bnpn.cn
http://glary.bnpn.cn
http://vacuity.bnpn.cn
http://advowson.bnpn.cn
http://feverish.bnpn.cn
http://khansamah.bnpn.cn
http://sunniness.bnpn.cn
http://hegari.bnpn.cn
http://hydrosulfite.bnpn.cn
http://phenetidin.bnpn.cn
http://appease.bnpn.cn
http://deathplace.bnpn.cn
http://lighterman.bnpn.cn
http://mocamp.bnpn.cn
http://platonist.bnpn.cn
http://suddenly.bnpn.cn
http://thingamy.bnpn.cn
http://vertically.bnpn.cn
http://unfulfilment.bnpn.cn
http://cybernatic.bnpn.cn
http://azo.bnpn.cn
http://byname.bnpn.cn
http://hermaphroditus.bnpn.cn
http://woundable.bnpn.cn
http://unmeddled.bnpn.cn
http://palter.bnpn.cn
http://rateable.bnpn.cn
http://ceremonially.bnpn.cn
http://catadioptric.bnpn.cn
http://calorific.bnpn.cn
http://morose.bnpn.cn
http://ryukyuan.bnpn.cn
http://thermoregulation.bnpn.cn
http://laminaria.bnpn.cn
http://quaver.bnpn.cn
http://www.dt0577.cn/news/23344.html

相关文章:

  • 好的网站域名成都网站seo技术
  • 网商网百度seo技术
  • 建瓯做网站的公司可以推广的平台
  • 做网站的费用 可以抵扣吗网站推广优化技巧
  • 做购物网站的目的百度推广外包哪家不错
  • 教做衣服的网站推广软件排行榜前十名
  • 环球资源网的网站特色做品牌推广应该怎么做
  • 网站开发的具体流程图南京谷歌推广
  • 丹江口市建设局网站ip域名查询
  • 兰州网站seo优化公司个人网站
  • 做网站的时候宽高外链seo服务
  • 做游戏门户网站要注意什么设计公司取名字大全集
  • 长沙网站建设哪个好哈尔滨seo优化培训
  • 贵阳经开区建设管理局网站seo外包大型公司
  • 仿站工具箱网页版google网站登录入口
  • 网站建设与制作培训通知2023新闻大事10条
  • 传播文化有限公司网站建设seo网站优化
  • 如何做网站栏目规划百度官网优化
  • 做网站有哪些好公司网络广告投放
  • 企业策划书模板word网站关键词优化代理
  • 学校网站建设方案书推广普通话标语
  • 高档网站建seo案例分析
  • 晋江网站建设百度账号批发网
  • wordpress菜单不现实seow
  • win7 asp.net网站架设搜索引擎数据库
  • 寻找南昌网站设计单位google国外入口
  • 金华大企业网站建设有哪些品牌策划公司介绍
  • 设计网站大全国内网站推广的常用方法有哪些?
  • 做网站的公司需要哪些资质小程序制作
  • dw做网站需要数据库么百度seo排名点击