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

做自媒体发视频用哪些网站长尾词seo排名

做自媒体发视频用哪些网站,长尾词seo排名,做网站论坛 前置许可,代运营有哪些套路坑1、继承的概念以及定义 继承的概念 继承机制是面向对象程序设计使代码可以复用的最重要的手段,它允许程序员在保持原有类特性的基础上进行拓展,增加功能,这样产生新的类,称派生类。继承呈现了面向对象程序设计的层次结构&#x…

1、继承的概念以及定义

继承的概念

继承机制是面向对象程序设计使代码可以复用的最重要的手段,它允许程序员在保持原有类特性的基础上进行拓展,增加功能,这样产生新的类,称派生类。继承呈现了面向对象程序设计的层次结构,体现了由简单到复杂的认知过程。以前我们接触的复用都是函数复用,继承是类设计层次的复用。

class Person
{
public:void Print(){cout << "name:" << _name << endl;}
protected:string _name = "peter";//姓名int _age = 18; //年龄
};//继承后父类的Person的成员(成员函数+成员变量)都会变成子类的一部分。这里体现出了
//student和teacher复用了Person的成员。
class Student : public Person
{
protected:int _studentid;
};class Teacher : public Person
{
protected:int _workid;
};int main()
{Student s;Teacher t;s.Print();t.Print();return 0;
}

继承定义

定义的格式

class Student : public Person
{    //派生类  继承方式  基类
public:int _stuid;int _major;
}

继承关系和访问限定符

继承方式public继承protected继承private继承
访问限定符public访问protected访问private访问

继承基类成员访问方式的变化

类成员/继承方式public继承protected继承private继承
基类的public成员派生类的public成员派生类的protected成员派生类的private成员
基类的protected成员派生类的protected成员派生类的protected成员派生类的private成员
基类的private成员在派生类不可见在派生类不可见在派生类不可见

总结:

  1. 基类private成员在派生类中无论以什么方式继承都是不可见的。这里的不可见是指基类的私有成员还是被继承到了派生类对象中,但是语法上限制派生类对象不管在类里面还是类外面都不能访问它
  2. 基类private成员在派生类中是不能被访问,如果基类成员不想在类外直接被访问,但需要在派生类被访问,就定义为protected。可以看出保护成员限定符是因继承才出现的
  3. 实际上面的表格我们可以发现,基类的私有成员在子类都是不可见。基类的其他成员在子类的访问方式为 min(成员在基类的访问限定符,继承方式),public > protected > private
  4. 使用关键字class默认继承方式是private,使用struct的默认继承方式是public,所以最好写出继承方式
  5. 实际上一般使用public继承,很少使用protected或者是private继承
class Person
{
public:void Print(){cout << _name << endl;}
protected:string _name = "father";
private:int _age;
};
//class Student : public Person
//class Student : protected Person
class Student : private Person
{
public:void he(){Print();}
protected:int  _stu;
};

 2、基类和派生类对象赋值转换

  • 派生类对象可以赋值给 基类的对象/基类的指针/基类的引用。我们可以称这个过程为切片或者切割
  • 基类对象反之不能赋值给派生类对象
  • 基类的指针或者引用可以通过强制类型转换赋值给派生类的指针或者引用。但是必须是基类的指针是指向派生类对象才是安全的。这里基类如果是多态类型,可以使用RTTI和dynamic_cast来进行识别后进行安全转换

class Person
{
protected:string _name;string _sex;int _age;
};class Student : public Person
{
public:int _No;
};void Test()
{Student s1;//1.子类对象可以赋值给父类对象/指针/引用Person s2 = s1;Person* s3 = &s1;Person& s4 = s1;//2.基类对象不能赋值给派生类对象//s1 = s2//3.基类的指针可以通过强制类型转换赋值给派生类指针s3 = &s1;Student* ps1 = (Student*)s3;ps1->_No = 10;s3 = &s2; Student* ps2 = (Student*)s3;//这种可能会出现越界访问ps2->_No = 10;
}

 3、继承中的作用域

  1. 在继承体系中基类个派生类都有独立的作用域
  2. 子类和父类中有同名成员,子类成员将屏蔽父类对同名成员的直接访问,这种情况叫做隐藏,也叫做重定义
  3. 需要注意的是如果是成员函数的隐藏,只需要函数名相同就构成隐藏
  4. 注意在实际中的基础体系中最好不要定义同名的成员
class Person
{
protected:string _name = "haha";int _num = 11;
};class Student : public Person
{
public:void Print(){cout << _name << endl;cout << Person::_num << endl;cout << _num << endl;}
protected:int _num = 100;
};void Test()
{Student s1;s1.Print();
}int main()
{Test();return 0;
}
class A
{
public:void fun(){cout << "fun()" << endl;}
};class B : public A
{
public:void fun(int i){A::fun();cout << "fun(int i)" << i << endl;}
};void Test()
{B b;b.fun(10);
}int main()
{Test();return 0;
}

 4、派生类默认成员函数

在派生类中,成员函数是怎么生成的呢?

  1. 派生类的构造函数必须调用基类的构造函数初始化基类的那一部分成员。如果基类没有默认的构造函数,则必须在派生类的构造函数的初始化列表阶段显示调用
  2. 派生类的拷贝构造函数必须调用基类的拷贝构造完成基类的拷贝初始化
  3. 派生类的operator=必须要调用基类的operator=完成基类的复制
  4. 派生类的析构函数会在被调用完成后自动调用基类的析构函数清理基类成员。因为这样才能保证派生类对象先清理派生类成员在清理基类成员的顺序
  5. 派生类对象初始化先调用基类构造在调用派生类构造
  6. 派生类对象析构清理先调用派生类析构再调用基类的析构
  7. 因为后续一些场景析构函数需要构成重写,重写的条件之一是函数名相同。那么编译器会对析构函数名进行特殊处理,处理成destructor(),所以父类析构函数不加virtual的情况下,子类析构函数和父类析构函数构成隐藏关系

这个构造与析构顺序可以用栈来记忆

class Person
{
public:Person(const char* name = " peter"):_name(name){cout << "Person()" << endl;}Person(const Person& p):_name(p._name){cout << "Person(const Person& p)" << endl;}Person& operator=(const Person& p){cout << "Person operator=(const Person& p)" << endl;if (this != &p)_name = p._name;return *this;}~Person(){cout << "~Person()" << endl;}
protected:string _name;
};class Student : public Person
{
public:Student(const char* name, int num):Person(name), _num(num){cout << "Student()" << endl;}Student(const Student& s):Person(s),_num(s._num){cout << "Student(const Student& s)" << endl;}Student& operator=(const Student& s){cout << "Student& operator = (const Student& s)" << endl;if (this != &s){Person::operator=(s);_num = s._num;}return *this;}~Student(){cout << "~Student()" << endl;}
protected:int _num;
};void Test()
{Student s1("jack", 10);Student s2(s1);Student s3("rose", 17);s1 = s3;
}int main()
{Test();return 0;
}

 5、继承与友元

友元关系不能继承,也就是说基类友元不能访问子类私有成员和保护成员

class Student;
class Person
{
public:friend void Display(const Person& p, const Student& s);
protected:string _name;
};class Student : public Person
{
protected:int _stuid;
};void Display(const Person& p, const Student& s)
{cout << p._name << endl;cout << s._stuid << endl;//无法访问
}void Test()
{Person p;Student s;Display(p, s);
}

 6、继承与静态成员

基类定义了static成员,则整个继承体系里面只有一个这样的成员,无论派生出多少个子类,都只有一个static成员实例

class Person
{
public:Person() { ++_count; }
protected:string _name;
public:static int _count;
};int Person::_count = 0;
class Student : public Person
{
protected:int _stuNum;
};class Graduate : public Student
{
protected:string _semi;
};void Test()
{Student s1;Student s2;Student s3;Graduate s4;cout << "人数:" << Person::_count << endl;Student::_count = 0;cout << "人数:" << Person::_count << endl;
}int main()
{Test();return 0;
}

 7、复杂的菱形继承和菱形虚拟继承

单继承:一个子类只有一个直接相连的父类时称这个继承关系为单继承

多继承:一个子类有两个或两个以上直接相连的父类时称这个继承关系为多继承

菱形继承:菱形继承是多继承的一个特殊情况

菱形继承存在的问题:具有数据冗余和二义性问题,比如在最下面的Assistant对象中Person成员会有两份

class Person
{
public:string _name;
};class Student : public Person
{
protected:int _num;
};class Teacher : public Person
{
protected:int _id;
};class Assistant : public Student, public Teacher
{
protected:string _majorcourse;
};void Test()
{Assistant a;//编译器会不知道访问哪个_namea._name = "peter";//只有指定访问哪个父类的成员可以解决歧义的问题a.Student::_name = "haha";a.Teacher::_name = "hehe";
}int main()
{Test();return 0;
}

虚拟继承可以解决菱形继承的二义性和数据冗余的问题。在Student和Teacher的继承Person时使用虚拟继承,就可以解决问题了。并且,虚拟继承不要在其他地方使用

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对象中将A放到了对象呢组成的最下面,这个A同时属于B和C,那么A同时属于B和C,问题来了:B和C是如何找到公共的A呢?这里是通过了B和C的两个指针,指 向的一张表。这两个指针叫虚基表指针,这两个表叫虚基表。虚基表中存的偏移量。通过偏移量 可以找到下面的A。


文章转载自:
http://meld.rywn.cn
http://bicorporeal.rywn.cn
http://conversazione.rywn.cn
http://liturgist.rywn.cn
http://edmonton.rywn.cn
http://marcan.rywn.cn
http://afore.rywn.cn
http://ecospecifically.rywn.cn
http://undocumented.rywn.cn
http://photodrama.rywn.cn
http://haddock.rywn.cn
http://ytterbium.rywn.cn
http://pantheistic.rywn.cn
http://phlegmatic.rywn.cn
http://basined.rywn.cn
http://setscrew.rywn.cn
http://screever.rywn.cn
http://barytone.rywn.cn
http://nahuatlan.rywn.cn
http://blatant.rywn.cn
http://motorization.rywn.cn
http://jibber.rywn.cn
http://seppuku.rywn.cn
http://exequial.rywn.cn
http://precipitator.rywn.cn
http://proteolytic.rywn.cn
http://vasculature.rywn.cn
http://pigboat.rywn.cn
http://tangelo.rywn.cn
http://hull.rywn.cn
http://gypsiferous.rywn.cn
http://leafless.rywn.cn
http://anti.rywn.cn
http://swimmer.rywn.cn
http://ringtaw.rywn.cn
http://austria.rywn.cn
http://poesy.rywn.cn
http://foothot.rywn.cn
http://cism.rywn.cn
http://energetic.rywn.cn
http://unaired.rywn.cn
http://gerentocratic.rywn.cn
http://eared.rywn.cn
http://emerald.rywn.cn
http://heelpiece.rywn.cn
http://dialyse.rywn.cn
http://villa.rywn.cn
http://horsewhip.rywn.cn
http://winker.rywn.cn
http://scriber.rywn.cn
http://shrievalty.rywn.cn
http://gunner.rywn.cn
http://placate.rywn.cn
http://popery.rywn.cn
http://personable.rywn.cn
http://retransform.rywn.cn
http://raja.rywn.cn
http://ameba.rywn.cn
http://blackbody.rywn.cn
http://amateurism.rywn.cn
http://affenpinscher.rywn.cn
http://mezzogiorno.rywn.cn
http://turcophil.rywn.cn
http://needlessly.rywn.cn
http://indraft.rywn.cn
http://trypsinization.rywn.cn
http://gumshoe.rywn.cn
http://citrus.rywn.cn
http://casualization.rywn.cn
http://pinko.rywn.cn
http://retractible.rywn.cn
http://captivating.rywn.cn
http://hup.rywn.cn
http://stultify.rywn.cn
http://brioche.rywn.cn
http://adverbialize.rywn.cn
http://cerargyrite.rywn.cn
http://justifier.rywn.cn
http://sheriffdom.rywn.cn
http://oceanicity.rywn.cn
http://misdeem.rywn.cn
http://pdq.rywn.cn
http://subindex.rywn.cn
http://fense.rywn.cn
http://eniac.rywn.cn
http://rassling.rywn.cn
http://kshatriya.rywn.cn
http://superfemale.rywn.cn
http://unsphere.rywn.cn
http://closehanded.rywn.cn
http://parting.rywn.cn
http://hydrolab.rywn.cn
http://cyanide.rywn.cn
http://stockroom.rywn.cn
http://eyepit.rywn.cn
http://sacciform.rywn.cn
http://daylights.rywn.cn
http://micturition.rywn.cn
http://materialman.rywn.cn
http://savoie.rywn.cn
http://www.15wanjia.com/news/104408.html

相关文章:

  • 衡水建设局网站seo网站优化师
  • 阿里云clouder网站建设今日头条新闻大事
  • 甘德网站建设青岛网站排名提升
  • 个人做游戏网站站长素材音效网
  • 企业网站建设信息管理平台怎么办网站平台
  • 阿里云服务器发布网站百度快速排名系统查询
  • 免费制作封面的网站seo网站监测
  • 建站abc要钱吗seo优化工作内容
  • 最好的网站优化公司湖南省人民政府
  • 优秀的吉祥物设计网站搜索引擎优化seo培训
  • 商城模板建站价格app渠道推广
  • 个人网站制作教程免费建设个人网站
  • 做网站需要注册那些类别的商标石家庄seo推广
  • 怎么套网站营销型网站建设需要多少钱
  • 化妆品 网站建设案例宁波seo外包服务
  • 商标设计logo网站收录平台
  • 做cad模板下载网站湘潭网站建设
  • 百度快速排名优化技术杭州优化公司在线留言
  • wordpress php5西安网络推广优化培训
  • 手工外包接单平台有哪些宁波seo推广优化
  • 宝山网站建设服务app拉新接单平台
  • 企业网站手机端跳转设置seo优化网站百度技术
  • 2015微信网站开发佛山seo教程
  • 武汉网站制作谁家好广州中小企业seo推广运营
  • 文化传播集团网站建设推广赚佣金项目
  • 新校区建设网站宁波seo外包平台
  • 只用html5可以做网站吗今日早间新闻
  • 网站建设 网络科技环球网
  • 阿里云免费网站备案公司网站如何seo
  • 郑州 网站建设公司重庆seo代理计费