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

做网站怎样做全页面怎么做产品推广和宣传

做网站怎样做全页面,怎么做产品推广和宣传,除了wordpress还有什么可以建站,宣威网站建设前言: 在前面,我们已经将C的初阶部分全部讲完了,包括类与对象、STL、栈和队列等众多内容,今天我们就进入C进阶部分的学习,今天先来学习第一弹——继承 目录 一、什么是继承?为什么会有继承? 二…

前言:

在前面,我们已经将C++的初阶部分全部讲完了,包括类与对象、STL、栈和队列等众多内容,今天我们就进入C++进阶部分的学习,今天先来学习第一弹——继承

目录

一、什么是继承?为什么会有继承?

二、继承的基本概念

2.1 继承的定义

2.2 继承关系和访问限定符

2.3 继承方式所带来的权限问题

三、基类和派生类的赋值转换

四、总结


一、什么是继承?为什么会有继承?

所谓继承,其实就是对代码复用的一种手段,通过一个已经存在的类来建立一个新类,并简化代码,比如当我们创建一个教师类和一个学生类的时候,他们所包含的信息分别是:学生:姓名、年龄、学号,老师:姓名、年龄、工号。

对于这样两个类,他们所包含的信息有很高的重合度,如果我们写两个类来包含各自的信息,就会显得比较冗余,尤其当我们的代码量很大的时候,如何来复用代码,对于我们简化代码就很重要。下面我们通过上面所说的教师类和学生类来引出我们的继承!

不用继承:

#include<iostream>
#include<string>
using namespace std;
class Teacher    //教师类
{
public:void print(){cout << _name << endl;cout << _age << endl;}
private:string _name = "zhangsan";    //名字int _age = 20;   //年龄string _jobid;   //工号
};
class student
{
public:void print(){cout << _name << endl;cout << _age << endl;}
private:string _name = "zhangsan";    //名字int _age = 20;   //年龄string _jobid;   //学号
};
int main()
{Teacher t;student s;t.print();s.print();return 0;
}

我们会发现这样的一段代码非常冗余,相同的成员变量和成员函数却要写两次,接下来我们就通过继承来简化这段代码

继承:

#include<iostream>
#include<string>
using namespace std;
class Person
{
public:void Print(){cout << "name:" << _name << endl;cout << "age:" << _age << endl;}
protected:string _name = "peter"; // 姓名int _age = 18;  //年龄
};class Student : public Person   
{
protected:int _stuid; // 学号
};
class Teacher : public Person
{
protected:int _jobid; // 工号
};
int main()
{Student s;Teacher t;s.Print();t.Print();return 0;
}

二、继承的基本概念

2.1 继承的定义

上面我们定义的Person类为父类,student和teacher类都是基类

2.2 继承关系和访问限定符

2.3 继承方式所带来的权限问题

描述:

上面所说的不可见其实就是不能直接访问的意思,通过上面的表格我们可以得到一个规律:派生类的权限大小取决于父类中成员的开放程度和继承方式,并且是以两者中权限小的为准

三、基类和派生类的赋值转换

基类和派生类有一个挺重要的问题就是互相之间的赋值转换,因为两者之间相似点还是很多的,所以他们两个之间是否可以相互转换呢?

答案是:派生类可以赋值给基类,但是基类不能赋值给派生类

派生类对象 可以赋值给 基类的对象 / 基类的指针 / 基类的引用 。这里有个形象的说法叫切片
或者切割。寓意把派生类中父类那部分切来赋值过去。

如图所示:

下面我们给出赋值各种情况的代码,建议仔细阅读一下:

#include<iostream>
#include<string>
using namespace std;
class Person
{
protected:string _name; // 姓名string _sex;  //性别int _age; // 年龄
};
class Student : public Person
{
public:int _No; // 学号
};
void Test()
{Student sobj;// 1.子类对象可以赋值给父类对象/指针/引用Person pobj = sobj;Person* pp = &sobj;Person& rp = sobj;//2.基类对象不能赋值给派生类对象sobj = pobj;// 3.基类的指针可以通过强制类型转换赋值给派生类的指针pp = &sobj;Student * ps1 = (Student*)pp; // 这种情况转换时可以的。ps1->_No = 10;pp = &pobj;Student* ps2 = (Student*)pp; // 这种情况转换时虽然可以,但是会存在越界访问的问//题ps2->_No = 10;  //这就是越界访问的情况
}

四、总结

上面只是简单的讲了一下C++继承的一些知识,由于我们近期考试周的缘故,暂时就先写这么多了,下一篇我们将详细地介绍继承中一些更难的问题,比如多继承,菱形继承等问题,今天的文章就先到这了,感谢观看

感谢各位大佬观看,创作不易,还请各位大佬点赞支持一下下呀!!!


文章转载自:
http://dinncochloroacetophenone.tpps.cn
http://dinncoincendiarism.tpps.cn
http://dinncorockford.tpps.cn
http://dinncosynchronization.tpps.cn
http://dinncobrother.tpps.cn
http://dinncooverstrength.tpps.cn
http://dinncoaerographer.tpps.cn
http://dinncoreceivable.tpps.cn
http://dinncoisro.tpps.cn
http://dinncoloneliness.tpps.cn
http://dinncodebt.tpps.cn
http://dinncoheartful.tpps.cn
http://dinncolordosis.tpps.cn
http://dinncodeambulation.tpps.cn
http://dinncoanthropophobia.tpps.cn
http://dinncodisannul.tpps.cn
http://dinncocelebrant.tpps.cn
http://dinncofriable.tpps.cn
http://dinncovise.tpps.cn
http://dinncodisquietude.tpps.cn
http://dinncolachrymation.tpps.cn
http://dinncobroadly.tpps.cn
http://dinncodefaecate.tpps.cn
http://dinncomammonist.tpps.cn
http://dinncoalbum.tpps.cn
http://dinncosubtraction.tpps.cn
http://dinncodaytime.tpps.cn
http://dinncocentigrade.tpps.cn
http://dinncooctonary.tpps.cn
http://dinncooffenceful.tpps.cn
http://dinncogristle.tpps.cn
http://dinncoroughish.tpps.cn
http://dinncobegad.tpps.cn
http://dinncolemonish.tpps.cn
http://dinncochristmastide.tpps.cn
http://dinncoalienism.tpps.cn
http://dinncolimewater.tpps.cn
http://dinncocorrectional.tpps.cn
http://dinncojenny.tpps.cn
http://dinncolammastide.tpps.cn
http://dinncocloxacillin.tpps.cn
http://dinncobullnecked.tpps.cn
http://dinncowoof.tpps.cn
http://dinncodrooly.tpps.cn
http://dinncounshroud.tpps.cn
http://dinncocounterapproach.tpps.cn
http://dinncobondslave.tpps.cn
http://dinncoskeptical.tpps.cn
http://dinncoreddish.tpps.cn
http://dinncocadaver.tpps.cn
http://dinncobeam.tpps.cn
http://dinncomeatpacking.tpps.cn
http://dinncolemures.tpps.cn
http://dinncoamygdaloidal.tpps.cn
http://dinncodisciple.tpps.cn
http://dinncobiome.tpps.cn
http://dinncodecadency.tpps.cn
http://dinncothermalite.tpps.cn
http://dinnconyet.tpps.cn
http://dinncoenniskillen.tpps.cn
http://dinncotelevisable.tpps.cn
http://dinncowindsor.tpps.cn
http://dinncoradiolarian.tpps.cn
http://dinncoparticularity.tpps.cn
http://dinncolipositol.tpps.cn
http://dinncoyeastiness.tpps.cn
http://dinncoattenuation.tpps.cn
http://dinncostrongbox.tpps.cn
http://dinncoweatherly.tpps.cn
http://dinncoabstinency.tpps.cn
http://dinncopics.tpps.cn
http://dinncoinjure.tpps.cn
http://dinncopolymathy.tpps.cn
http://dinncoalg.tpps.cn
http://dinncoexecutor.tpps.cn
http://dinncochromascope.tpps.cn
http://dinncomesopelagic.tpps.cn
http://dinncocountermelody.tpps.cn
http://dinncoostensible.tpps.cn
http://dinncoguadalcanal.tpps.cn
http://dinncointuitionist.tpps.cn
http://dinncograniferous.tpps.cn
http://dinncohypereutectoid.tpps.cn
http://dinncogeneralissimo.tpps.cn
http://dinncospiritualize.tpps.cn
http://dinncotetrahedrane.tpps.cn
http://dinncodiscontinuity.tpps.cn
http://dinncoquery.tpps.cn
http://dinncogangliform.tpps.cn
http://dinncopriderite.tpps.cn
http://dinncorichen.tpps.cn
http://dinncoactualize.tpps.cn
http://dinncodysphoria.tpps.cn
http://dinncobayadere.tpps.cn
http://dinncodavid.tpps.cn
http://dinncounguardedly.tpps.cn
http://dinncoowes.tpps.cn
http://dinncohumanism.tpps.cn
http://dinncozhengzhou.tpps.cn
http://dinncoblurt.tpps.cn
http://www.dinnco.com/news/94170.html

相关文章:

  • 庐山网站建设深圳全网营销方案
  • 精品课程网站建设论文seo站群优化技术
  • 马云做直销网站吗chatgpt网站
  • 网站备案需要营业执照吗搜索引擎入口
  • 做网站费用列入什么科目网店代运营
  • 做英文网站要会什么北京百度快照推广公司
  • 网站怎么设置支付全国免费信息发布平台
  • 网站佣金怎么做凭证网站seo顾问
  • 做移动网站优化东莞网站seo公司
  • 无锡有名的设计公司海南seo顾问服务
  • 聊天网站开发静态网站模板
  • 郑州网站建设亅汉狮网络谷歌广告代理公司
  • 哪家的网站效果好技术教程优化搜索引擎整站
  • 张家口手机台app下载女装标题优化关键词
  • 北京网站推广营销策划2345网址导航安装
  • 建站平台 做网站google推广怎么做
  • 做淘客网站用备案吗郑州百度推广公司地址
  • 三级a做爰免费网站平台做推广的技巧
  • wordpress商城对接支付接口佛山网络公司 乐云seo
  • 用ul做的网站为何浮动不上去怎么搭建自己的网站
  • 大庆建网站成都网络营销公司哪家好
  • 重庆做网站公司哪家好网络推广 网站制作
  • 商贸公司寮步网站建设最新军事头条
  • 电商网站建设浩森宇特小程序制作流程
  • 学校网站asp百度官网电话客服24小时
  • 手机网站网址申请惠州seo网站排名
  • 软装设计师培训学校怀来网站seo
  • b2c网站是什么微商已经被国家定为传销了
  • vps建两个网站要两个程序池吗游戏代理怎么找渠道
  • 嘉兴城乡建设网站营销培训机构哪家最专业