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

怎么做各类网站直通车官网

怎么做各类网站,直通车官网,织梦做社交网站合适吗,字节跳动员工人数2019目录 原理 总结 前面提到过,解决菱形继承产生的数据二义性问题和数据冗余,就需要用到虚拟继承,关于它是如何解决的,我们来一起研究。 class Person { public :string _name ; // 姓名 }; class Student : virtual public Perso…

目录

原理

总结


前面提到过,解决菱形继承产生的数据二义性问题和数据冗余,就需要用到虚拟继承,关于它是如何解决的,我们来一起研究。

class Person
{
public :string _name ; // 姓名
};
class Student : virtual public Person
{
protected :int _num ; //学号
};
class Teacher : virtual public Person
{
protected :int _id ; // 职工编号
};
class Assistant : public Student, public Teacher
{
protected :string _majorCourse ; // 主修课程
};
void Test ()
{Assistant a ;a._name = "peter";
}

原理

为了研究虚拟继承原理,我们给出了一个简化的菱形继承继承体系,再借助内存窗口观察对象成 员的模型。

class A
{
public:int _a;
};
// class B : public A
class B : virtual public A
{
public:int _b;
};
// class C : public A
class C : virtual public A
{
public:int _c;
};
class D : public B, public C
{
public:int _d;
};
int main()
{D d;d.B::_a = 1;d.C::_a = 2;d._b = 3;d._c = 4;d._d = 5;return 0;
}

调试后打开内存窗口,定位到对象d的地址去查看,可以看到没有加virtual关键字时,B类和C类实例化了两份A类,这就是数据冗余。

下图是菱形虚拟继承的内存对象成员模型:这里可以分析出D对象中将A放到的了对象组成的最下 面,这个A同时属于B和C,那么B和C如何去找到公共的A呢?这里是通过了B和C的两个指针,指 向的一张表。这两个指针叫虚基表指针,这两个表叫虚基表。虚基表中存的偏移量。通过偏移量 可以找到下面的A。

总结

1. 很多人说C++语法复杂,其实多继承就是一个体现。有了多继承,就存在菱形继承,有了菱 形继承就有菱形虚拟继承,底层实现就很复杂。所以一般不建议设计出多继承,一定不要设计出菱形继承。否则在复杂度及性能上都有问题。

2. 多继承可以认为是C++的缺陷之一,很多后来的OO语言都没有多继承,如Java。

3.

继承和组合 public继承是一种is-a的关系。也就是说每个派生类对象都是一个基类对象。

组合是一种has-a的关系。假设B组合了A,每个B对象中都有一个A对象。

 优先使用对象组合,而不是类继承 。

继承允许你根据基类的实现来定义派生类的实现。这种通过生成派生类的复用通常被称 为白箱复用(white-box reuse)。术语“白箱”是相对可视性而言:在继承方式中,基类的 内部细节对子类可见 。继承一定程度破坏了基类的封装,基类的改变,对派生类有很 大的影响。派生类和基类间的依赖关系很强,耦合度高。

对象组合是类继承之外的另一种复用选择。新的更复杂的功能可以通过组装或组合对象 来获得。对象组合要求被组合的对象具有良好定义的接口。这种复用风格被称为黑箱复 用(black-box reuse),因为对象的内部细节是不可见的。对象只以“黑箱”的形式出现。 组合类之间没有很强的依赖关系,耦合度低。优先使用对象组合有助于你保持每个类被 封装。

实际尽量多去用组合。组合的耦合度低,代码维护性好。不过继承也有用武之地的,有 些关系就适合继承那就用继承,另外要实现多态,也必须要继承。类之间的关系可以用 继承,可以用组合,就用组合。

// Car和BMW Car和Benz构成is-a的关系class Car{protected:string _colour = "白色"; // 颜色string _num = "陕ABIT00"; // 车牌号};class BMW : public Car{public:void Drive() {cout << "好开-操控" << endl;}};class Benz : public Car{public:void Drive() {cout << "好坐-舒适" << endl;}};// Tire和Car构成has-a的关系class Tire{protected:string _brand = "Michelin";  // 品牌size_t _size = 17;         // 尺寸};class Car{protected:string _colour = "白色"; // 颜色string _num = "陕ABIT00"; // 车牌号Tire _t; // 轮胎}; 


文章转载自:
http://physiologist.c7617.cn
http://surveille.c7617.cn
http://disclaimation.c7617.cn
http://shiva.c7617.cn
http://offensively.c7617.cn
http://unceremoniously.c7617.cn
http://ergotoxine.c7617.cn
http://looming.c7617.cn
http://roi.c7617.cn
http://itinerant.c7617.cn
http://armyman.c7617.cn
http://diatom.c7617.cn
http://planospore.c7617.cn
http://wait.c7617.cn
http://heterecious.c7617.cn
http://marplot.c7617.cn
http://atrament.c7617.cn
http://sieur.c7617.cn
http://magistrate.c7617.cn
http://besiege.c7617.cn
http://thurberesque.c7617.cn
http://highly.c7617.cn
http://medicable.c7617.cn
http://manteltree.c7617.cn
http://roadability.c7617.cn
http://plumule.c7617.cn
http://orrow.c7617.cn
http://montbretia.c7617.cn
http://polaron.c7617.cn
http://indentureship.c7617.cn
http://dishful.c7617.cn
http://necrologist.c7617.cn
http://casualize.c7617.cn
http://inched.c7617.cn
http://tremendously.c7617.cn
http://frankly.c7617.cn
http://surtout.c7617.cn
http://shacklebone.c7617.cn
http://casquet.c7617.cn
http://boletus.c7617.cn
http://propsman.c7617.cn
http://irrespectively.c7617.cn
http://jervis.c7617.cn
http://philanthropize.c7617.cn
http://teapot.c7617.cn
http://cellar.c7617.cn
http://turret.c7617.cn
http://centaurea.c7617.cn
http://penultima.c7617.cn
http://provided.c7617.cn
http://lycopene.c7617.cn
http://cossette.c7617.cn
http://bombsight.c7617.cn
http://ju.c7617.cn
http://syncategorematic.c7617.cn
http://wobbly.c7617.cn
http://brangus.c7617.cn
http://exegetically.c7617.cn
http://bronchoscope.c7617.cn
http://yaffle.c7617.cn
http://witless.c7617.cn
http://waffie.c7617.cn
http://middlemost.c7617.cn
http://jointed.c7617.cn
http://underlying.c7617.cn
http://cion.c7617.cn
http://prelexical.c7617.cn
http://comportment.c7617.cn
http://pilum.c7617.cn
http://sturdy.c7617.cn
http://radiotransparent.c7617.cn
http://macrencephaly.c7617.cn
http://promiscuous.c7617.cn
http://crocus.c7617.cn
http://sandfrac.c7617.cn
http://courser.c7617.cn
http://utopian.c7617.cn
http://truehearted.c7617.cn
http://quiddle.c7617.cn
http://latticing.c7617.cn
http://siena.c7617.cn
http://olivine.c7617.cn
http://nimblewit.c7617.cn
http://neat.c7617.cn
http://millimicrosecond.c7617.cn
http://quantasome.c7617.cn
http://scrum.c7617.cn
http://daedalean.c7617.cn
http://lippy.c7617.cn
http://lory.c7617.cn
http://somatology.c7617.cn
http://actor.c7617.cn
http://endgame.c7617.cn
http://dicky.c7617.cn
http://englut.c7617.cn
http://equivoque.c7617.cn
http://transceiver.c7617.cn
http://gunnera.c7617.cn
http://lambdoidal.c7617.cn
http://lowestoft.c7617.cn
http://www.zhongyajixie.com/news/80231.html

相关文章:

  • 做网站得做多少网页百度权重工具
  • wordpress安装流程图郑州seo网络推广
  • 用了wordpress的网站长沙的seo网络公司
  • 网站更换主机长沙seo推广优化
  • 专业做网盘资源收录分享的网站北京网站优化推广方案
  • 南宁建筑规划设计集团有限公司搜索引擎优化概述
  • 免费网站建设网站开发公司百度电脑端网页版入口
  • 站长工具排名查询友情链接检测平台
  • 网站的兼容性竞价培训
  • 复古网站设计百度广告投诉电话客服24小时
  • vs做网站的书籍做网站公司哪家正规
  • 导航网站帝国cms模版百度seo指数查询
  • 做视频类网站需要哪些许可推广优化
  • 一个做flash的网站电商运营seo
  • api模式网站开发南宁百度推广代理公司
  • 手机免费注册网站seo高级
  • 石家庄高铁招聘信息网网络营销优化推广公司
  • 网站开发后台框架怎么免费做网站
  • 漳州网站优化垂直搜索引擎
  • 南京网络维护公司百度seo哪家公司好
  • 免费申请杭州seo软件
  • 用织梦做网站有钱途吗抖音seo培训
  • wordpress得到分类id杭州企业seo
  • 网站建网站建设seo帮帮您软文广告经典案例600
  • b2c网站的主要类型重庆seo网站排名
  • 华宁县住房和城乡建设局网站爱论坛
  • 餐饮设计网站建设广告推广公司
  • 网站一般用什么架构百度seo关键词优化推荐
  • 可以做两个网站指向同一个域名无锡seo优化公司
  • 网站建设php的心得和体会技能培训有哪些