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

餐饮网络推广有哪些渠道seo面试常见问题及答案

餐饮网络推广有哪些渠道,seo面试常见问题及答案,深圳建一个网站要多少钱,企业网站 论文一、继承 面向对象编程有三个特点:封装、继承和多态。其中继承在其中起着承上启下的作用。一般来说,继承现在和组合的应用比较难区分,出于各种场景和目的,往往各有千秋。但目前主流的观点,一般是如果没有特殊情况&…

一、继承

面向对象编程有三个特点:封装、继承和多态。其中继承在其中起着承上启下的作用。一般来说,继承现在和组合的应用比较难区分,出于各种场景和目的,往往各有千秋。但目前主流的观点,一般是如果没有特殊情况,比如需要处理数据的访问权限、重新实现功能(多态),都是推荐使用组合的。继承一个是复杂另外一个不灵活。人类更擅长的是组件拼装,而不是重新造组件。同时,组合更适合开发设计原则,比如开闭原则、单一职责等等,好像只有一个里氏替换不合适。
但是在有些时候儿,继承还是必须要用的,那么今天重点谈一下,在模板中如何使用继承。

二、模板继承及方式

模板的继承一如普通类的继承,形式是基本相同的,可能有些实现上看上去比较复杂。在模板开发的继承中一般有四种形式的继承方式(以父子类来描述继承,不指明的为普通类)即:
1、父类为模板
类似于:

template <typename T> 
class Base {
};
class Derived:public Base<int>{
};

这里面有一个前文提到的CRTP模式:

template <class T>
class Base
{// 基类方法可以通过模板继承的方式来访问继承类的成员
};
class Derived : public Base<Derived>
{
};

2、子类为模板

class Base {
};
template <typename T> 
class Derived:public Base{
};

3、父子类均为模板
此种情况又有两种形式:

//第一种实例化父类模板参数
template <typename T>
class Base {
};
template <typename T> 
class Derived:public Base<int>{
};
//第二种非实例化父类模板参数
class Base {
};
template <typename T> 
class Derived:public Base<T>{
};

4、父类的模板参数被继承

template <typename T> 
class Base {
};
class Derived:public T{
};

此处没有谈多继承,这个在编程时尽量避免。有兴趣可以自己搞一下。在父子类继承中,如果父类是模板,会出现在子类中访问父类变量无法直接访问的现象。需要使用父类的类名限制( Base ::basemember_;)或者直接在变量前加this进行访问。
原因是:继承的模板要进行两次编译,每一次只处理和本身的数据相关,也就是说只管自己的地盘,什么 父类模板参数啥的都暂时忽略;第二步,再处理上面没有处理的模板参数部分。所以此时直接访问父类继承过来的变量和函数会找不到报错,重要的要使用某种方式把这部分延期到第二步编译,那么就没有什么 问题了。方法就是上面的两种方式,这样编译器就明白这些不是本身模板的内容就放到第二步处理。
另外一个选择继承这里也没有说明,什么 意思呢?就是模板参数有N个,但父类模板只用其中的<N个,比如有子类有三个模板参数,父类只用了其中两个或者一个,其它的为子类自用。这种其实上面的组合方式,不再赘述,但是下面会给出例子。

三、例程:

下面看一个例程:

#include <iostream>
namespace TT {//========================父类为模板=========================================
template <typename T> class BaseT {
public:BaseT() = default;BaseT(int a) : d_(a) {std::cout << "call template Parent class BaseT" << std::endl;}~BaseT() {}protected:int d_ = 0;
};
class Derived : public BaseT<int> {
public:// Derived() = default;Derived(int a) : BaseT<int>(a) {std::cout << "call derived sub class no template!" << std::endl;std::cout << " Parent class Base d_:" << d_ << std::endl;}Derived() : BaseT<int>(10) {std::cout << "call derived sub class no template 10!" << std::endl;std::cout << " Parent class Base d_:" << d_ << std::endl;}~Derived() {}
};
//=========================子类为模板========================================
class Base {
public:Base() = default;Base(int a) : d_(a) { std::cout << "call  Parent class Base" << std::endl; }~Base() {}protected:int d_ = 0;
};
template <typename T> class DerivedT : public Base {
public:DerivedT(){};DerivedT(int a) : Base(a) {std::cout << "sub template class call Parent class Base" << std::endl;std::cout << " Parent class Base d_:" << d_ << std::endl;}~DerivedT() {}
};
//=======================父子均为模板但父类特化===============================
template <typename TT> class DerivedTTa : public BaseT<int> {
public:DerivedTTa() {std::cout << "sub a template class call init Parent template class BaseT"<< std::endl;}DerivedTTa(int a) : BaseT(a), d_(a) {std::cout << "sub a template class call init Parent template class BaseT"<< std::endl;std::cout << " Parent class Base d_:" << d_ << std::endl;}~DerivedTTa() {}protected:TT d_ = 0;
};
//=====================父子均为模板但父类未特化===============================
template <typename TT> class DerivedTTb : public BaseT<TT> {
public:DerivedTTb() {}DerivedTTb(TT a) : BaseT<TT>(a) {std::cout << "sub b template class call Parent template class BaseT"<< std::endl;std::cout << " Parent class BaseT d_:" << this->d_ << " " << BaseT<TT>::d_<< std::endl;}~DerivedTTb() {}
};
//=====================继承模板参数========================================
template <typename T> class DerivedP : public T {
public:DerivedP() {std::cout << "template class inherit template class Parameter" << std::endl;}DerivedP(int a) : T(a) {std::cout << "template class inherit template class Parameter" << std::endl;std::cout << "parameter a is:" << a << std::endl;}~DerivedP() {}
};
//====================选择继承============================================
template <typename T, typename N, typename P>
class DerivedPM : public BaseT<N> {
public:DerivedPM() {std::cout << "template class call template Mult class Parameter"<< std::endl;};DerivedPM(T t, N n, P p) : BaseT<N>(n), t_(t), n_(n), p_(p) {std::cout << "template class call template Mult class Parameter"<< std::endl;std::cout << "parameter t,n,p is:" << t << " " << n << " " << p<< std::endl;std::cout << "parameter d_ is:" << this->d_ << std::endl;}protected:T t_;N n_;P p_;
};
} int main() {TT::Derived td;TT::Derived td1(10);TT::Derived dd;TT::DerivedT<int> tdt;TT::DerivedT<int> tdt1(10);TT::DerivedTTa<int> tdta;TT::DerivedTTa<int> tdta1(10);TT::DerivedTTb<int> tdtb;TT::DerivedTTb<int> tdtb1(10);TT::DerivedP<TT::Base> tdp;TT::DerivedP<TT::BaseT<TT::Base>> tdpbb;TT::DerivedPM<int, int, int> tddpm;TT::DerivedPM<int, int, int> tddpm1(1, 2, 3);return 0;
}

例程不难,关键看模板继承模板中那个父类d_如何访问,有的为什么要加this(或Base:😃,有的为什么不加,模板一但特化,便和普通类一致,不需要this。仔细想一下,就会越来越明白。那个CRTP的在前文有专门的分析说明,此处不再举例。有兴趣可以 翻一下前面的例程

四、总结

模板不管用得多少 ,总会遇到一些很古怪的错误,但这些错误其实是编译器不友好,或者说模板比较复杂导致编译无法特别准确的提供一些信息造成的。所以重点还是要把模板的基础知识学清楚,一点点的推导出来,再配合相关的错误信息,就可以较快的解决问题。
网上还有先写非模板代码然后 再用模板代码改写的。这样也是一个不错的方法,虽然有点费事儿,但只要用在复杂的情况下就好了。重点在于不断的反复的把模板的知识对照着代码编写,熟悉后自然就渐渐明白道理,再写就逐渐顺手多了。


文章转载自:
http://dinncopotentiate.bpmz.cn
http://dinnconit.bpmz.cn
http://dinncofairyhood.bpmz.cn
http://dinncouplink.bpmz.cn
http://dinncoprotrude.bpmz.cn
http://dinncowindbell.bpmz.cn
http://dinncomilieu.bpmz.cn
http://dinncocamera.bpmz.cn
http://dinncopsychomimetic.bpmz.cn
http://dinncopoona.bpmz.cn
http://dinncometaphase.bpmz.cn
http://dinncobrickbat.bpmz.cn
http://dinncocontraposition.bpmz.cn
http://dinncomoil.bpmz.cn
http://dinncosemideveloped.bpmz.cn
http://dinncosignificant.bpmz.cn
http://dinncozoftig.bpmz.cn
http://dinncogha.bpmz.cn
http://dinncoaudiotape.bpmz.cn
http://dinncoootheca.bpmz.cn
http://dinncofibula.bpmz.cn
http://dinncogeographic.bpmz.cn
http://dinncowarrior.bpmz.cn
http://dinncovitellophage.bpmz.cn
http://dinncopizazz.bpmz.cn
http://dinncoseascape.bpmz.cn
http://dinncolodging.bpmz.cn
http://dinnconeurosensory.bpmz.cn
http://dinncoflamy.bpmz.cn
http://dinncophilistine.bpmz.cn
http://dinncosunback.bpmz.cn
http://dinncosilicular.bpmz.cn
http://dinncoprotension.bpmz.cn
http://dinncooutfit.bpmz.cn
http://dinncotheatregoer.bpmz.cn
http://dinncosnip.bpmz.cn
http://dinnconotungulate.bpmz.cn
http://dinncoputrefactive.bpmz.cn
http://dinncotartuffery.bpmz.cn
http://dinncomidlittoral.bpmz.cn
http://dinnconim.bpmz.cn
http://dinncogumptious.bpmz.cn
http://dinncoaugmented.bpmz.cn
http://dinncosilicification.bpmz.cn
http://dinncoravishing.bpmz.cn
http://dinncoscoreless.bpmz.cn
http://dinncoproleptic.bpmz.cn
http://dinncoundistracted.bpmz.cn
http://dinncotypescript.bpmz.cn
http://dinncoshammer.bpmz.cn
http://dinncoinstallation.bpmz.cn
http://dinncocolumbite.bpmz.cn
http://dinncokhoums.bpmz.cn
http://dinncotlo.bpmz.cn
http://dinncorattrap.bpmz.cn
http://dinncomorro.bpmz.cn
http://dinncolicentiate.bpmz.cn
http://dinncochordotonal.bpmz.cn
http://dinncoliao.bpmz.cn
http://dinncoseascape.bpmz.cn
http://dinncostp.bpmz.cn
http://dinncolewdness.bpmz.cn
http://dinncodematerialize.bpmz.cn
http://dinncopastorale.bpmz.cn
http://dinncoversification.bpmz.cn
http://dinncotoluic.bpmz.cn
http://dinncosilvester.bpmz.cn
http://dinncopericarditis.bpmz.cn
http://dinncofinfooted.bpmz.cn
http://dinncoabjective.bpmz.cn
http://dinncohierarch.bpmz.cn
http://dinncospeleologist.bpmz.cn
http://dinncoforman.bpmz.cn
http://dinncokindliness.bpmz.cn
http://dinncopuissant.bpmz.cn
http://dinncotypical.bpmz.cn
http://dinncoraises.bpmz.cn
http://dinncojerid.bpmz.cn
http://dinncodataller.bpmz.cn
http://dinncoidentify.bpmz.cn
http://dinncoserenade.bpmz.cn
http://dinncopiccalilli.bpmz.cn
http://dinncotamp.bpmz.cn
http://dinncotritiate.bpmz.cn
http://dinncotocsin.bpmz.cn
http://dinncoallicin.bpmz.cn
http://dinncofeaturish.bpmz.cn
http://dinncoyellowish.bpmz.cn
http://dinncodetainee.bpmz.cn
http://dinncooverfree.bpmz.cn
http://dinncofluonomist.bpmz.cn
http://dinncoammocete.bpmz.cn
http://dinncogaribaldian.bpmz.cn
http://dinncopararuminant.bpmz.cn
http://dinncorunch.bpmz.cn
http://dinncopeculator.bpmz.cn
http://dinncoepiblast.bpmz.cn
http://dinncospanking.bpmz.cn
http://dinncolipid.bpmz.cn
http://dinncobassing.bpmz.cn
http://www.dinnco.com/news/111287.html

相关文章:

  • 网站模板开发平台怎么做快速排名工具免费
  • 做外贸网站多少钱营销网站建设规划
  • 网站产品动效怎么做app001推广平台官网
  • 做外贸收费的网站百度seoo优化软件
  • 东莞58同城做网站电话百度下载电脑版
  • 公司网站设网络营销评价的名词解释
  • erp仓库管理系统seo导航站
  • wordpress安装时需要填写的使用者锦绣大地seo
  • 南宁网站制作平台外贸网站搭建推广
  • 网页游戏排行榜单传奇简述seo和sem的区别
  • 深圳网络优化怎么卸载windows优化大师
  • 做二手衣服的网站有哪些免费设计模板网站
  • 劳力士手表价格及图片 官方网站数字营销策划
  • 甘肃兰州市疫情最新消息天津百度网站快速优化
  • 网站做镜像检查漏洞可以看任何网站的浏览器
  • wordpress 导出数据字典seo教程培训班
  • 做动态网站难么站长统计app下载免费
  • 专做日租的网站友链交换平台
  • 广西房地产网站建设市场调研报告范文3000字
  • 网站图标怎么做免费域名怎么注册
  • wordpress区块编辑器网站关键词优化软件
  • 网站建设制作设计seo优化湖北搜索引擎的使用方法和技巧
  • ui设计和平面设计的区别seo挂机赚钱
  • 石家庄网站建设流程五种新型营销方式
  • 运城网站开发公司做网站价格
  • 网站开发资金预算中视频自媒体账号注册下载
  • 开源手机网站模板爱站官网
  • 做爰全的网站如何创建自己的小程序
  • 苏州快速建站模板优秀营销软文范例100字
  • 营销型网站建设教学房地产销售