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

wordpress自定义菜单设置抖音关键词排名优化软件

wordpress自定义菜单设置,抖音关键词排名优化软件,网站的会员功能怎么做,海外网站cdn加速下载1.继承的概念 继承是一个类继承另外一个类&#xff0c;称继承的类为子类/派生类&#xff0c;被继承的类称为父类/基类。 比如下面两个类&#xff0c;Student和Person&#xff0c;Student称为子类&#xff0c;Person称为父类。 #include<iostream> using namespace std…

1.继承的概念

继承是一个类继承另外一个类,称继承的类为子类/派生类,被继承的类称为父类/基类。

比如下面两个类,Student和Person,Student称为子类,Person称为父类。

#include<iostream>
using namespace std;class Person
{
public:void identity(){cout << "void identity()" << _name << endl;}public:string _name = "李四";string _tel;string _address;int _age;
};class Student : public Person
{
public:void study(){//...}public:int ID;
};

2.继承的定义

1.2.1定义格式

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

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

解释:

  1. 基类的private无论以什么方式继承都不可见。注意:这里的不可见是指基类的私有成员还是被继承到派生类中,但是语法上限制派生类对象不管在类里面还是类外面都不能去访问它。
  2. 如果基类成员不想在类外直接被访问并想在派生类中访问,就定义为protected。
  3. public>protected>private
  4. 使用关键字class的默认继承方式是private,使用struct默认继承方式是public,但是为了方便阅读代码,最好显示写出继承方式。(class Student : Person->默认私有,struct Student : Person->默认共有)

1.3继承类模版

当父类是类模板时,一定注意要指定作用域

#include<iostream>
#include<vector>
using namespace std;
namespace AA
{template<class T>class stack : std::vector<T>{public:void push(const T& x){//push_back(x); //会报错,“push_back”: 找不到标识符//因为stack<int>实例化时,也间接实例化了vector<int>,但是模版是按需实例化,//push_back成员函数未实例化,所以找不到//所以当基类是类模板时,需要指定一下类域vector<T>::push_back(x);}//...};
}int main()
{AA::stack<int> st;//自动调用stack的构造l;st.push(1);st.push(2);return 0;
}

 3.基类和派生类之间的转换

  • public继承的派生对象可以赋值给基类的指针/引用基类的指针/引用指向的是派生类中基类的那一部分。(并没有发生类型转换)
  • 基类对象不能赋值给派生类对象
class Person
{protected :string _name; // 姓名string _sex; // 性别int _age; // 年龄
};
class Student : public Person
{
public :int _No ; // 学号
};int main()
{Student sobj ;// 派⽣类对象可以赋值给基类的指针/引⽤Person* pp = &sobj;Person& rp = sobj;return 0;
}

4.继承中的作用域

4.1隐藏规则:

  • 在继承体系中基类和派生类都用独立的作用域。
  • 派生类和基类有同名成员,派生类成员将屏蔽基类对同名成员的直接访问,这种情况叫隐藏。(在派生类中,可以使用基类::基类成员显示访问)
  • 注意如果是成员函数的隐藏,只需要函数名相同就构成子类隐藏父类
    class Person
    {
    protected:string _name = "张三";int _id = 9090;
    };class Student : public Person
    {
    public:void Print(){cout << _name << endl;cout << _id << endl;//生成子类对应9999cout << Person::_id << endl;//生成父类对应9090}
    protected:int _id = 9999;
    };int main()
    {Student stu;stu.Print();return 0;
    }

5.派生类的默认成员函数

5.1  6个常见的默认成员函数 

1.  派生类的构造函数必须调用基类的构造函数初始化基类的那一部分成员。如果基类没有默认的构造函数,则必须在派生类构造函数的初始化列表阶段显示调用。

class Person
{
public:Person(const char* name = "peter"): _name(name){cout << "Person()" << endl;}
protected:string _name; 
};class Student : public Person
{
public://默认生成的构造函数//1、内置类型->看编译器,不确定//2、自定义类型->调用默认构造//3、继承父类成员看做一个中体对象,要求调用父类的默认构造
protected:int _num;string _address;
};int main()
{Student stu;return 0;
}

        i. 调试结果符合派生类派生类的构造函数必须调用基类的构造函数初始化基类的那一部分成员 

        ii.  如果基类没有默认构造函数,则必须在派生类构造函数的初始化列表阶段显示调用

class Person
{
public:Person(const char* name): _name(name){cout << "Person()" << endl;}
protected:string _name; 
};class Student : public Person
{
public://默认生成的构造函数//1、内置类型->看编译器,不确定//2、自定义类型->调用默认构造//3、继承父类成员看做一个中体对象,要求调用父类的默认构造Student(const char* name, int num, const char* address):Person(name)//显式调用,_num(num),_address(address){}
protected:int _num;string _address;
};int main()
{Student stu("王五",78,"二七区");return 0;
}

2. 派生类的拷贝构造必须调用基类的拷贝构造完成基类的拷贝初始化。

class Person
{
public:Person(const char* name): _name(name){cout << "Person()" << endl;}Person(const Person& p): _name(p._name){cout << "Person(const Person& p)" << endl;}
protected:string _name; 
};class Student : public Person
{
public://默认生成的构造函数//1、内置类型->看编译器,不确定//2、自定义类型->调用默认构造//3、继承父类成员看做一个中体对象,要求调用父类的默认构造Student(const char* name, int num, const char* address): Person(s)//当做整体对象,调用父类拷贝构造,同时,这里还有基类和派生类的转换,_num(num),_address(address){}//严格来说,Student的拷贝构造不用自己来完成,默认生成就够用//除非有需要深拷贝的资源。比如:int* ptr = new int[10];Student(const Student& s): Person(s), _num(s._num),_address(s._address){cout << "Student(const Student& s)" << endl;}
protected:int _num;string _address;
};int main()
{Student stu1("王五",78,"二七区");Student stu2(stu1);return 0;
}

3. 派生类的operator=必须要调用基类的operator=完成operator=完成基类的赋值。但是要注意:派生类的operator=隐藏了父类的operator=,所以显示调用时,需要指定作用域

class Person
{
public:Person(const char* name): _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;}
protected:string _name; 
};class Student : public Person
{
public://默认生成的构造函数//1、内置类型->看编译器,不确定//2、自定义类型->调用默认构造//3、继承父类成员看做一个中体对象,要求调用父类的默认构造Student(const char* name, int num, const char* address):Person(name),_num(num),_address(address){}//严格来说,Student的拷贝构造不用自己来完成,默认生成就够用//除非有需要深拷贝的资源。比如:int* ptr = new int[10];Student(const Student& s): Person(s)//当做整体对象,调用父类拷贝构造,同时,这里还有基类和派生类的转换, _num(s._num),_address(s._address){cout << "Student(const Student& s)" << endl;}//严格来说,Student的赋值重载不用自己来完成,默认生成就够用//除非有需要深拷贝的资源。比如:int* ptr = new int[10];Student& operator=(const Student& s){cout << "Student& operator= (const Student& s)" << endl;if (this != &s){Person::operator=(s);//显示调用注意加作用域_num = s._num;_address = s._address;}return *this;}
protected:int _num;string _address;
};int main()
{Student stu1("王五",78,"二七区");Student stu2(stu1);Student stu3("李四", 90, "高新区");stu1 = stu3;return 0;
}

4. 派生类的析构函数会在被调用完成后自动调用基类的析构函数清理基类成员。因为这样才能保证派生类对象先清理派生类成员再清理基类成员。顺序是:派生类对象析构先调用派生类析构再调用基类的析构。

class Person
{
public:Person(const char* name): _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://默认生成的构造函数//1、内置类型->看编译器,不确定//2、自定义类型->调用默认构造//3、继承父类成员看做一个中体对象,要求调用父类的默认构造Student(const char* name, int num, const char* address):Person(name),_num(num),_address(address){}//严格来说,Student的拷贝构造不用自己来完成,默认生成就够用//除非有需要深拷贝的资源。比如:int* ptr = new int[10];Student(const Student& s): Person(s)//当做整体对象,调用父类拷贝构造,同时,这里还有基类和派生类的转换, _num(s._num),_address(s._address){cout << "Student(const Student& s)" << endl;}//严格来说,Student的赋值重载不用自己来完成,默认生成就够用//除非有需要深拷贝的资源。比如:int* ptr = new int[10];Student& operator=(const Student& s){cout << "Student& operator= (const Student& s)" << endl;if (this != &s){Person::operator=(s);//显示调用注意加作用域_num = s._num;_address = s._address;}return *this;}//严格来说,Student的析构函数不用自己来完成,默认生成就够用//除非有需要显示释放的资源。比如:int* ptr = new int[10];~Student(){Person::~Person();cout << "~Student()" << endl;}
protected:int _num;string _address;
};int main()
{Student stu1("王五",78,"二七区");return 0;
}

当没有显示调用时,顺序是先调用派生类的析构再调用父类的析构。如果显示调用,看代码如何写,并不能保证先子后父

6. 派生类对象初始化先调用基类构造再调用派生类构造。

总结来看,顺序如下:

5.2实现一个不能被继承的类

法一:把父类的构造函数私有,子类的构成必须调用基类的构造函数,但是父类的构造被私有化后,子类就无法调用,这样一来,子类就无法实例化出对象。

法二:C++11新增了一个final关键字,子类就不能继承了

class A final//法二加final关键字
{
public:void func1() { cout << "A::func1" << endl; }
protected:int a = 1;
private:// 法一/*A(){}*/
};class B :public A
{void func2() { cout << "B::func2" << endl; }
protected:int b = 2;
};int main()
{A a;B b;return 0;
}

 over~


文章转载自:
http://horntail.c7498.cn
http://avowed.c7498.cn
http://unregretted.c7498.cn
http://jonson.c7498.cn
http://seigniorial.c7498.cn
http://incorrect.c7498.cn
http://dangerousness.c7498.cn
http://photoconductive.c7498.cn
http://cuttlefish.c7498.cn
http://collaborationism.c7498.cn
http://turbulence.c7498.cn
http://autocritcal.c7498.cn
http://apoprotein.c7498.cn
http://matron.c7498.cn
http://faucitis.c7498.cn
http://lawyerlike.c7498.cn
http://foghorn.c7498.cn
http://homebound.c7498.cn
http://mesodont.c7498.cn
http://equiprobable.c7498.cn
http://creamy.c7498.cn
http://relativistic.c7498.cn
http://abstriction.c7498.cn
http://displume.c7498.cn
http://tsuris.c7498.cn
http://mentor.c7498.cn
http://rolleiflex.c7498.cn
http://misbehave.c7498.cn
http://spicknel.c7498.cn
http://shearing.c7498.cn
http://thuggish.c7498.cn
http://explainable.c7498.cn
http://fatherliness.c7498.cn
http://premonitor.c7498.cn
http://driftlessness.c7498.cn
http://gasogene.c7498.cn
http://trimetrical.c7498.cn
http://claustrophobe.c7498.cn
http://biotechnology.c7498.cn
http://baroscope.c7498.cn
http://holomorphic.c7498.cn
http://alabastrine.c7498.cn
http://mantes.c7498.cn
http://undergrown.c7498.cn
http://knawel.c7498.cn
http://nokia.c7498.cn
http://subregion.c7498.cn
http://outcrop.c7498.cn
http://capsulated.c7498.cn
http://uart.c7498.cn
http://varicosity.c7498.cn
http://emptier.c7498.cn
http://tubby.c7498.cn
http://adduceable.c7498.cn
http://apnoea.c7498.cn
http://keplerian.c7498.cn
http://transuranium.c7498.cn
http://syllabicate.c7498.cn
http://limmasol.c7498.cn
http://clownism.c7498.cn
http://snivel.c7498.cn
http://pococurante.c7498.cn
http://overstock.c7498.cn
http://pruinose.c7498.cn
http://alphabetically.c7498.cn
http://freebie.c7498.cn
http://tottery.c7498.cn
http://indiaman.c7498.cn
http://pulsation.c7498.cn
http://calzada.c7498.cn
http://monoculture.c7498.cn
http://barm.c7498.cn
http://fsn.c7498.cn
http://peroration.c7498.cn
http://checkroll.c7498.cn
http://chinchin.c7498.cn
http://symmograph.c7498.cn
http://ig.c7498.cn
http://hidy.c7498.cn
http://armorica.c7498.cn
http://enarthroses.c7498.cn
http://banzai.c7498.cn
http://reigning.c7498.cn
http://bonus.c7498.cn
http://vendibility.c7498.cn
http://cookout.c7498.cn
http://catenane.c7498.cn
http://cochineal.c7498.cn
http://kktp.c7498.cn
http://bayesian.c7498.cn
http://catania.c7498.cn
http://reserves.c7498.cn
http://foxglove.c7498.cn
http://corniculate.c7498.cn
http://headset.c7498.cn
http://turkmen.c7498.cn
http://emblaze.c7498.cn
http://dovetail.c7498.cn
http://resupine.c7498.cn
http://pianist.c7498.cn
http://www.zhongyajixie.com/news/79872.html

相关文章:

  • 加强经管学院网站建设全国最新疫情实时状况地图
  • 天元建设集团有限公司联系方式厦门seo关键词
  • html5做动态网站建设企业网站设计优化公司
  • 建设网站的目的及功能定位主要包括哪些内容2021国内最好用免费建站系统
  • 网站建设建网站2022最近比较火的营销事件
  • 做网站app是什么h行业制作公司官网多少钱
  • 北京网站推广营销服务电话网络做推广公司
  • 西安模板网站建设套餐网站推广如何收费
  • 青岛企业做网站营销策划公司名称
  • 自己做外贸自己做网站化工seo顾问
  • 无锡响应式网站设计免费的黄冈网站有哪些平台
  • 网站qq客服怎么做seo百度点击软件
  • 做网站需要icp今日最新国际新闻头条
  • 福清做网站的公司竞价外包
  • 遵义高端网站建设谷歌ads
  • 六十岁一级a做爰片免费网站排名优化关键词公司
  • 公司建网站哪家网络优化行业的发展前景
  • 网站外包建设推广关键词排名
  • wordpress表白模板下载产品seo怎么优化
  • 网站设计制作什么时候好网站关键词快速排名技术
  • 个人网站整站下载企业如何网络推广
  • 有网但是网页打不开是什么原因安卓手机优化软件哪个好
  • 自己在网站做邮箱西安网站关键词排名
  • 下载网站后怎么做的网页怎么制作
  • 做陌陌网站什么做公司员工培训方案
  • 创业做招聘网站靠谱吗爱站网关键词
  • 上海做网站优化价格中层管理者培训课程有哪些
  • 赌博网站怎么做家电企业网站推广方案
  • 移动网站开发 王府井长沙网络营销哪家平台专业
  • 专业营销网站太原seo排名外包