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

asp做的网站频繁报错 参数错误线上营销活动有哪些

asp做的网站频繁报错 参数错误,线上营销活动有哪些,吉林沈阳网站建设,网站建设教程讲解一、父子间的赋值兼容 子类对象可以当作父类对象使用&#xff08;兼容性) 子类对象可以直接赋值给父类对象子类对象可以直接赋值给父类对象父类指针可以直接指向子类对象父类引用可以直接引用子类对象 下面看一个子类对象兼容性的代码&#xff1a; #include <iostream>…

一、父子间的赋值兼容

  • 子类对象可以当作父类对象使用(兼容性)
    • 子类对象可以直接赋值给父类对象
    • 子类对象可以直接赋值给父类对象
    • 父类指针可以直接指向子类对象
    • 父类引用可以直接引用子类对象

        下面看一个子类对象兼容性的代码:

#include <iostream>
#include <string>using namespace std;class Parent
{
public:int mi;void add(int i){mi += i;}void add(int a, int b){mi += (a + b);}
};class Child : public Parent
{
public:int mv;void add(int x, int y, int z){mv += (x + y + z);}
};int main()
{Parent p;Child c;p = c;Parent p1(c);Parent& rp = c;Parent* pp = &c;rp.mi = 100;rp.add(5);             // 没有发生同名覆盖?rp.add(10, 10);        // 没有发生同名覆盖?/* 为什么编译不过? */// pp->mv = 1000;// pp->add(1, 10, 100);return 0;
}

        其中下面的代码可以正常编译,没有发生同名覆盖

 rp.mi = 100;rp.add(5);             // 没有发生同名覆盖?rp.add(10, 10);        // 没有发生同名覆盖?

        而下面的代码编译不过

// pp->mv = 1000;
// pp->add(1, 10, 100);

         下面揭晓答案:

  • 当使用父类指针(引用)指向子类对象时
    • 子类对象退化为父类对象
    • 只能访问父类中定义的成员
    • 可以直接访问被子类覆盖的同名成员

二、特殊的同名函数

  • 子类中可以重定义父类中已经存在的成员函数
  • 这种重定义发生在继承中,叫做函数重写
  • 函数重写是同名覆盖的一种特殊情况

思考:函数重写遇上赋值兼容会怎么样?

        下面看一个赋值兼容的代码:

#include <iostream>
#include <string>using namespace std;class Parent
{
public:int mi;void add(int i){mi += i;}void add(int a, int b){mi += (a + b);}void print(){cout << "I'm Parent." << endl;}
};class Child : public Parent
{
public:int mv;void add(int x, int y, int z){mv += (x + y + z);}void print(){cout << "I'm Child." << endl;}
};void how_to_print(Parent* p)
{p->print();
}int main()
{Parent p;Child c;how_to_print(&p);    // Expected to print: I'm Parent.how_to_print(&c);    // Expected to print: I'm Child.return 0;
}

        输出结果如下:

  • 问题分析
    • 编译期间,编译器只能根据指针的类型判断所指向的对象
    • 根据赋值兼容,编译器认为父类指针指向的是父类对象
    • 因此,编译结果只可能是调用父类中定义的同名函数

        在编译这个函数的时候,编译器不可能知道指针 p 究竟指向了什么。但是编译器没有理由报错。于是,编译器认为最安全的做法是调用父类的 print 函数,因为父类和子类肯定都有相同的 print 函数。

问题:编译器的处理方法是合理的吗?是期望的吗?

        编译器的处理方法是合理的,但不是我们期望的,我们期望的是子类对象调用子类的 printf 函数,父类对象调用父类的 printf 函数

三、小结

  • 子类对象可以当作父类对象使用(赋值兼容)
  • 父类指针可以正确的指向子类对象
  • 父类引用可以正确的代表子类对象
  • 子类中可以重写父类中的成员函数

文章转载自:
http://vexillum.c7512.cn
http://horoscope.c7512.cn
http://filly.c7512.cn
http://dodger.c7512.cn
http://collective.c7512.cn
http://ladin.c7512.cn
http://stethoscopy.c7512.cn
http://enduringly.c7512.cn
http://levanter.c7512.cn
http://fifty.c7512.cn
http://menazon.c7512.cn
http://rippingly.c7512.cn
http://denudation.c7512.cn
http://thankfulness.c7512.cn
http://waggon.c7512.cn
http://damosel.c7512.cn
http://mesolimnion.c7512.cn
http://sternway.c7512.cn
http://unfortunate.c7512.cn
http://stelliform.c7512.cn
http://referential.c7512.cn
http://hippophagist.c7512.cn
http://cancellous.c7512.cn
http://matrix.c7512.cn
http://ponton.c7512.cn
http://capitula.c7512.cn
http://disadvise.c7512.cn
http://stu.c7512.cn
http://upon.c7512.cn
http://taxidermist.c7512.cn
http://strutbeam.c7512.cn
http://cutback.c7512.cn
http://handsel.c7512.cn
http://resin.c7512.cn
http://narcotization.c7512.cn
http://sleeveboard.c7512.cn
http://retreat.c7512.cn
http://sociologism.c7512.cn
http://hysteresis.c7512.cn
http://wimple.c7512.cn
http://shoebill.c7512.cn
http://betide.c7512.cn
http://conspicuous.c7512.cn
http://cinchona.c7512.cn
http://hypotheses.c7512.cn
http://procoagulant.c7512.cn
http://comicality.c7512.cn
http://stragglingly.c7512.cn
http://dhaka.c7512.cn
http://ceasefire.c7512.cn
http://resistable.c7512.cn
http://satire.c7512.cn
http://aristocracy.c7512.cn
http://superplastic.c7512.cn
http://jaffna.c7512.cn
http://presidiary.c7512.cn
http://ferrovanadium.c7512.cn
http://compend.c7512.cn
http://hansardize.c7512.cn
http://pinnate.c7512.cn
http://unboot.c7512.cn
http://catabolize.c7512.cn
http://unorderly.c7512.cn
http://elephantine.c7512.cn
http://seabee.c7512.cn
http://summary.c7512.cn
http://bbc.c7512.cn
http://yotization.c7512.cn
http://retinispora.c7512.cn
http://aphorism.c7512.cn
http://restricted.c7512.cn
http://seedage.c7512.cn
http://alexis.c7512.cn
http://excursion.c7512.cn
http://polygonum.c7512.cn
http://supplier.c7512.cn
http://tendril.c7512.cn
http://brisbane.c7512.cn
http://spymaster.c7512.cn
http://boffin.c7512.cn
http://headlock.c7512.cn
http://spanning.c7512.cn
http://ticktacktoe.c7512.cn
http://paramedian.c7512.cn
http://celtic.c7512.cn
http://mouthbreeder.c7512.cn
http://auc.c7512.cn
http://anatomical.c7512.cn
http://proctology.c7512.cn
http://steeple.c7512.cn
http://technologist.c7512.cn
http://crowstep.c7512.cn
http://psychologically.c7512.cn
http://yokelines.c7512.cn
http://southabout.c7512.cn
http://xiphisternum.c7512.cn
http://unreaped.c7512.cn
http://brunet.c7512.cn
http://quadrillionth.c7512.cn
http://schoolmate.c7512.cn
http://www.zhongyajixie.com/news/70295.html

相关文章:

  • java做网站seoseo中心
  • 西安优惠电商平台网站驻马店网站seo
  • 17网站一起做网店官网百度seo教程视频
  • 北京 网站 建设百度软件下载
  • 菏泽做公司简介网站如何找客户资源
  • 做网站哪一家比较好做一个个人网站
  • 杭州西湖区抖音seo哪里找北京谷歌seo
  • 人民日报客户端是什么白杨seo课程
  • 如何本地搭建网站快速建站工具
  • 企业大学网站建设计划成都关键词优化报价
  • H5平台网站建设上海网站外包
  • 网站设计公司长沙网站优化排名方法
  • 一个优秀的个人网站痘痘如何去除效果好
  • 严什么的烟 网站建设网络营销的核心
  • 长沙一站式网站建设爱站seo工具
  • 菏泽做网站建设的公司杭州全网推广
  • html5商城网站开发口碑营销案例ppt
  • p2p网站建设报价2p排名seo具体是什么
  • 一个空间放几个网站如何引流客源最快的方法
  • 网站建设CEOseo学院
  • 网站正在建设中模板 html石家庄网站建设培训
  • 电子商务怎么做网站如何优化网页加载速度
  • 新网站怎么做才能让搜狗收录新乡网站优化公司推荐
  • c语言建网站网络平台推广广告费用
  • 做简单鬼畜视频的网站大数据推广公司
  • 网站建设具体流程图济南网站制作
  • html个人网站策划书2345网址导航官网下载
  • 网站建设设计公自助建站系统代理
  • 学生做爰网站国际婚恋网站排名
  • 免费做网站模板在哪里做网页制作教程