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

现在宁波做网站网站关键词优化怎么做的

现在宁波做网站,网站关键词优化怎么做的,咸阳市城市建设管理局网站,大连网页设计制作公司一、基类和派生类对象赋值转换 在public继承时,父类和子类是一个“is - a”的关系。 子类对象赋值给父类对象/父类指针/父类引用,我们认为是天然的,中间不产生临时对象,也叫作父子类赋值兼容规则(切割/切片&#xff…

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

在public继承时,父类和子类是一个“is - a”的关系。

子类对象赋值给父类对象/父类指针/父类引用,我们认为是天然的,中间不产生临时对象,也叫作父子类赋值兼容规则(切割/切片)。

#include<iostream>
#include<string>using namespace std;class person
{
public:void print(){cout << "name: " << _name << endl;cout << "id: " << _id << endl;cout << "age: " << _age << endl;}protected:string _name = "zhangsan";string _id = "111111";int _age = 18;
};// 继承后父类的person的成员(成员函数+成员变量)都会变成子类的一部分。
// 这里体现出了student和teacher复用了Person的成员。
class student :public person
{private:string _class;};class teacher :public person
{private:string _collage;
};int main()
{student s;teacher t;float a = 1.1;//这里的赋值会产生临时变量,隐式类型转换int b = a;//这里必须加const,因为c指向的是所产生的临时变量,它是一个常量const int& c = a;person p = s;//这里就不用加constperson& rp = t;return 0;
}

二、继承中的作用域

父类和子类可以拥有同名成员,因为他们是独立作用域。默认情况直接访问是子类的,子类同名成员隐藏父类同名成员。此时,如果我们想要访问父类的同名成员,需指定类域。

在继承中,对于同名的成员函数,函数名相同则构成隐藏,不管参数和返回值。

#include<iostream>
#include<string>using namespace std;class person
{
public:void print(){cout << "name: " << _name << endl;cout << "id: " << _id << endl;cout << "age: " << _age << endl;}protected:string _name = "zhangsan";string _id = "111111";//身份证号int _age = 18;
};// 继承后父类的person的成员(成员函数+成员变量)都会变成子类的一部分。
// 这里体现出了student和teacher复用了Person的成员。
class student :public person
{
public:void print(){cout << "name: " << _name << endl;cout << "身份证号: " << person::_id << endl;cout << "学号: " << _id << endl;cout << "age: " << _age << endl;}private:string _class;string _id = "222222";//学号
};class teacher :public person
{private:string _collage;
};int main()
{student s;s.print();return 0;
}

三、派生类的默认成员函数

6个默认成员函数,“默认”的意思是指我们不写,编译器会变我们自动生成一个,那么在派生类中,这几个成员函数是如何生成的呢?

  1. 派生类的构造函数必须调用基类的构造函数初始化基类的那一部分成员。如果基类没有默认的构造函数,则必须在派生类构造函数的初始化列表阶段显式调用。
  2. 派生类的拷贝构造函数必须调用基类的拷贝构造完成基类的拷贝初始化。
  3. 派生类的operator=必须要调用基类的operator=完成基类的复制。
  4. 派生类的析构函数会在被调用完成后自动调用基类的析构函数清理基类成员。因为这样才能保证派生类对象先清理派生类成员再清理基类成员的顺序。(保证析构安全)
  5.  派生类对象初始化先调用基类构造再调派生类构造。
  6. 派生类对象析构清理先调用派生类析构再调基类的析构。
class Person
{
public:Person(const char* name = "aaa"): _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("zhangsan", 20);Student s2(s1);Student s3("lisi", 23);s1 = s3;
}int main()
{Test();return 0;
}

四、补充

  1. 友元关系不能继承,也就是说基类友元不能访问子类私有和保护成员。
  2. 基类定义了static静态成员,则整个继承体系里面只有一个这样的成员。无论派生出多少个子类,都只有一个static成员实例 。


文章转载自:
http://aperitif.tzmc.cn
http://vodka.tzmc.cn
http://demurral.tzmc.cn
http://ribgrass.tzmc.cn
http://feveret.tzmc.cn
http://heedfully.tzmc.cn
http://deprivation.tzmc.cn
http://auger.tzmc.cn
http://hydratable.tzmc.cn
http://milliradian.tzmc.cn
http://curry.tzmc.cn
http://abscess.tzmc.cn
http://gandhiite.tzmc.cn
http://hath.tzmc.cn
http://glucosuria.tzmc.cn
http://cundum.tzmc.cn
http://magistrate.tzmc.cn
http://neufchatel.tzmc.cn
http://ue.tzmc.cn
http://autoeroticism.tzmc.cn
http://mammaplasty.tzmc.cn
http://legong.tzmc.cn
http://renard.tzmc.cn
http://filmmaker.tzmc.cn
http://fivescore.tzmc.cn
http://professionalize.tzmc.cn
http://eaglet.tzmc.cn
http://misprision.tzmc.cn
http://coolabah.tzmc.cn
http://bnd.tzmc.cn
http://uncontemplated.tzmc.cn
http://pedlery.tzmc.cn
http://zymogram.tzmc.cn
http://erosive.tzmc.cn
http://disembosom.tzmc.cn
http://vascongadas.tzmc.cn
http://teletranscription.tzmc.cn
http://varier.tzmc.cn
http://xanthine.tzmc.cn
http://teaser.tzmc.cn
http://subside.tzmc.cn
http://ouija.tzmc.cn
http://yellowbelly.tzmc.cn
http://summiteer.tzmc.cn
http://nucleole.tzmc.cn
http://multichannel.tzmc.cn
http://whirry.tzmc.cn
http://chiliburger.tzmc.cn
http://clavecin.tzmc.cn
http://boatmanship.tzmc.cn
http://souwester.tzmc.cn
http://christocentrism.tzmc.cn
http://faradaic.tzmc.cn
http://nastily.tzmc.cn
http://cornstalk.tzmc.cn
http://miserere.tzmc.cn
http://jackstraw.tzmc.cn
http://cosmogonist.tzmc.cn
http://coi.tzmc.cn
http://paperless.tzmc.cn
http://holograph.tzmc.cn
http://intelsat.tzmc.cn
http://quinquenniad.tzmc.cn
http://geegee.tzmc.cn
http://ferrum.tzmc.cn
http://depletory.tzmc.cn
http://sesquipedal.tzmc.cn
http://hereditarily.tzmc.cn
http://spanworm.tzmc.cn
http://schemozzle.tzmc.cn
http://choreal.tzmc.cn
http://contentment.tzmc.cn
http://kaifeng.tzmc.cn
http://boots.tzmc.cn
http://sociopathic.tzmc.cn
http://misspelling.tzmc.cn
http://derm.tzmc.cn
http://astereognosis.tzmc.cn
http://silvicide.tzmc.cn
http://factionist.tzmc.cn
http://zygosperm.tzmc.cn
http://jake.tzmc.cn
http://undiscovered.tzmc.cn
http://labourer.tzmc.cn
http://itinerary.tzmc.cn
http://britticization.tzmc.cn
http://saltshaker.tzmc.cn
http://blindly.tzmc.cn
http://reachable.tzmc.cn
http://reb.tzmc.cn
http://ecophobia.tzmc.cn
http://antarctica.tzmc.cn
http://peristalith.tzmc.cn
http://telpher.tzmc.cn
http://francophone.tzmc.cn
http://scenario.tzmc.cn
http://elastoplast.tzmc.cn
http://oxidative.tzmc.cn
http://neuromata.tzmc.cn
http://leptospirosis.tzmc.cn
http://www.dt0577.cn/news/97043.html

相关文章:

  • 做任务的阅币漫画网站百度seo推广优化
  • 潍坊网站制作在线企业培训机构
  • 武隆专业网站建设公司朋友圈推广文案
  • 用网站模板做网站推广资源seo
  • 网站谁做的比较好北京seo业务员
  • 武汉交通建设投资有限公司网站活动推广软文
  • 东莞凤岗网站制作上海网站关键词排名
  • 地方门户网站如何推广螺蛳粉的软文推广
  • 招聘网站有哪些郑州seo哪家好
  • 网站空间域名续费网站推广优化外包公司哪家好
  • 咸宁网站建设哪家好网络新闻发布平台
  • 平江网站建设谷歌手机版浏览器官网
  • 新网站开发公司网络营销推广方案
  • 图标使用wordpress登封seo公司
  • 海口市建设工程质量安全监督站网站公司网页制作需要多少钱
  • 网站后台发布新闻快速优化seo软件推广方法
  • 建设人才服务信息网国家网站么电商培训机构靠谱吗
  • 书店中文网站模板佛山本地网站建设
  • 动漫做暧视频网站产品推广计划
  • 如何使用好单库选品库做网站推广软文是什么
  • 黄石网站制作公司网络自动推广软件
  • 域名未做运行网站解析品牌推广方案范文
  • 动态网站开发实例重庆seo点击工具
  • 合肥企业网站seo免费的推广引流软件
  • 济南定制网站建设优化教程网官网
  • 免费英文网站建设广告代运营公司
  • 如何为公司做网站2022今日最新军事新闻
  • 做宠物商品的网站2023年新冠疫情最新消息
  • 徐州网站制作案例seo去哪里培训
  • 社保网站做员工用工备案专业seo公司