text: (window.webpackJsonp=window.webpackJsonp||[]).push([[2],{166:function(t,s,n){t.exports=n.p+"assets/img/成员变量和非成员变量.abeeccdf.png"},167:function(t,s,n){t.exports=n.p+"assets/img/成员函数和非成员函数.18eaed6b.png"},168:function(t,s,n){t.exports=n.p+"assets/img/访问权限.ce788b0d.png"},169:function(t,s,n){t.exports=n.p+"assets/img/class中函数3大概念.43294c4e.png"},196:function(t,s,n){"use strict";n.r(s);var a=n(0),e=Object(a.a)({},(function(){var t=this,s=t.$createElement,a=t._self._c||s;return a("div",{staticClass:"content"},[t._m(0),t._v(" "),t._m(1),t._m(2),t._v(" "),a("p",[t._v("[TOC]")]),t._v(" "),t._m(3),t._v(" "),t._m(4),t._v(" "),t._m(5),t._v(" "),a("ul",[t._m(6),t._v(" "),a("li",[a("font",{staticStyle:{background:"yellow"}},[t._v("这也是Ｃ++语言和其它语言Java, Python的一个显著区别")])],1)]),t._v(" "),t._m(7),t._v(" "),t._m(8),t._v(" "),t._m(9),a("ul",[a("li",[t._v("参考"),a("a",{attrs:{href:"https://www.nowcoder.com/profile/2876549",target:"_blank",rel:"noopener noreferrer"}},[t._v("牛油的回答"),a("OutboundLink")],1)])]),t._v(" "),t._m(10),t._m(11),t._m(12),t._v(" "),t._m(13),t._v(" "),t._m(14),t._v(" "),t._m(15),t._v(" "),t._m(16),t._v(" "),t._m(17),t._m(18),t._v(" "),t._m(19),t._v(" "),t._m(20),t._m(21),t._m(22),t._v(" "),t._m(23),t._v(" "),t._m(24),t._v(" "),t._m(25),t._m(26),t._v(" "),t._m(27),t._v(" "),t._m(28),t._v(" "),a("img",{attrs:{src:n(166)}}),t._v(" "),t._m(29),t._v(" "),t._m(30),t._v(" "),t._m(31),t._v(" "),t._m(32),t._v(" "),t._m(33),t._v(" "),t._m(34),t._v(" "),t._m(35),t._v(" "),t._m(36),a("blockquote",[a("p",[t._v("参考自："),a("a",{attrs:{href:"https://www.huaweicloud.com/articles/4637f3d11eb3fd9a38e017041e23e50a.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("华为云"),a("OutboundLink")],1)])]),t._v(" "),t._m(37),t._v(" "),t._m(38),t._v(" "),t._m(39),t._v(" "),t._m(40),t._v(" "),a("img",{attrs:{src:n(167)}}),t._v(" "),a("blockquote",[a("p",[t._v("我的"),a("a",{attrs:{href:"http://naotu.baidu.com/file/02d2413a51829d0c29226a23718613ad?token=d83f2eb1c2d887a6",target:"_blank",rel:"noopener noreferrer"}},[t._v("百度脑图"),a("OutboundLink")],1)]),t._v(" "),t._m(41)]),t._v(" "),t._m(42),t._v(" "),t._m(43),t._v(" "),t._m(44),t._m(45),t._v(" "),a("ul",[t._m(46),t._v(" "),t._m(47),t._v(" "),a("li",[a("p",[t._v("🐾"),a("font",{staticStyle:{background:"yellow"}},[t._v("无法继承的『static成员函数』")])],1)]),t._v(" "),t._m(48),t._v(" "),t._m(49)]),t._v(" "),t._m(50),t._v(" "),t._m(51),t._v(" "),t._m(52),t._v(" "),t._m(53),t._v(" "),a("p",[t._v("书中说道："),a("font",{staticStyle:{background:"blue"}},[t._v("C++支持3种类型的**（member function）成员函数**")]),t._v("『记住下面的』")],1),t._v(" "),t._m(54),t._v(" "),t._m(55),t._v(" "),a("ul",[t._m(56),t._v(" "),a("li",[a("font",{staticStyle:{background:"yellow"}},[t._v("所以"),a("strong",[t._v("在成员函数")]),t._v("中，"),a("strong",[t._v("static")]),t._v("和"),a("strong",[t._v("const不能同时")]),t._v("修饰同一个成员函数")]),t._v("，因为static成员函数没有this指针。")],1)]),t._v(" "),t._m(57),t._m(58),t._v(" "),t._m(59),t._v(" "),a("ul",[a("li",[t._v("注意："),a("font",{staticStyle:{background:"yellow"}},[t._v("友元函数不是类的成员函数！")]),t._v("（"),a("strong",[t._v("欢聚时代")]),t._v("）")],1)]),t._v(" "),t._m(60),t._v(" "),t._m(61),t._v(" "),t._m(62),t._v(" "),a("blockquote",[a("p",[t._v("参考自：菜鸟教程"),a("a",{attrs:{href:"https://www.runoob.com/cplusplus/cpp-friend-functions.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("C++ 友元函数"),a("OutboundLink")],1)])]),t._v(" "),t._m(63),t._v(" "),a("p",[t._v("『『"),a("font",{staticStyle:{background:"yellow"}},[t._v("友元函数是不能被继承的")]),t._v("——解释，你父亲的朋友不能继承给你？』』，"),a("font",{staticStyle:{background:"yellow"}},[t._v("友元函数没有this指针")]),t._v("\n友元只是破坏了类的隐藏性和封装性，"),a("font",{staticStyle:{background:"yellow"}},[t._v("可以直接调用，不需要通过对象或者指针")])],1),t._v(" "),t._m(64),t._v(" "),t._m(65),t._v(" "),t._m(66),t._v(" "),t._m(67),t._v(" "),t._m(68),t._v(" "),t._m(69),t._v(" "),t._m(70),t._m(71),t._v(" "),t._m(72),t._v(" "),a("p",[t._v("分为：")]),t._v(" "),t._m(73),t._v(" "),t._m(74),t._m(75),t._v(" "),t._m(76),t._v(" "),t._m(77),t._v(" "),t._m(78),t._v(" "),t._m(79),t._v(" "),t._m(80),t._v(" "),t._m(81),t._v(" "),t._m(82),t._v(" "),t._m(83),t._v(" "),a("ul",[a("li",[t._v("类的成员有三种访问属性，分别是public、protected、private，"),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44308742&qid=1618#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("子类能够访问的成员"),a("OutboundLink")],1),t._v("是")])]),t._v(" "),t._m(84),t._v(" "),a("img",{attrs:{src:n(168)}}),t._v(" "),t._m(85),t._v(" "),t._m(86),t._v(" "),t._m(87),t._v(" "),t._m(88),t._v(" "),t._m(89),t._v(" "),t._m(90),t._v(" "),t._m(91),t._v(" "),t._m(92),t._v(" "),t._m(93),t._v(" "),a("ul",[a("li",[a("strong",[t._v("重写(Override)")]),t._v("：\n"),a("ul",[a("li",[t._v("也叫做"),a("strong",[t._v("覆盖")]),t._v("，也叫"),a("strong",[t._v("复写")]),t._v("，一般发生在子类和父类继承关系之间。子类"),a("strong",[t._v("重新定义")]),t._v("父类中有相同名称和参数的"),a("font",{staticStyle:{background:"yellow"}},[t._v("『"),a("strong",[t._v("虚函数")]),t._v("』")])],1)])]),t._v(" "),a("li",[a("strong",[t._v("重定义")]),t._v("：\n"),a("ul",[a("li",[t._v("也叫做"),a("strong",[t._v("隐藏")]),t._v("，子类"),a("strong",[t._v("重新定义")]),t._v("父类中有相同名称的"),a("font",{staticStyle:{background:"yellow"}},[t._v("『"),a("strong",[t._v("非虚函数")]),t._v("』 ")]),t._v("( 参数列表可以不同 ) ，指派生类的函数屏蔽了与其同名的基类函数。可以理解成发生在继承中的重载。")],1)])])]),t._v(" "),a("blockquote",[a("p",[t._v("参考："),a("a",{attrs:{href:"https://blog.csdn.net/u010275850/article/details/45583705",target:"_blank",rel:"noopener noreferrer"}},[t._v("C++_重载、重写和重定义的区别"),a("OutboundLink")],1)])]),t._v(" "),a("p",[t._v("PS：但是，从很多英语教材上面，来说，重定义和重写都是单词（override），理解参考第4节")]),t._v(" "),t._m(94),t._v(" "),t._m(95),t._v(" "),t._m(96),t._v(" "),a("blockquote",[a("p",[t._v("参考："),a("a",{attrs:{href:"https://blog.csdn.net/jszhangyili/article/details/7570311",target:"_blank",rel:"noopener noreferrer"}},[t._v("CSDN的jszhangyili博客"),a("OutboundLink")],1)])]),t._v(" "),a("img",{attrs:{src:n(169)}}),t._v(" "),t._m(97),t._v(" "),a("ul",[a("li",[t._v("Overload\n"),a("ul",[a("li",[a("strong",[t._v("相同作用域")]),t._v("『可以不是class中』\n"),a("ul",[a("li",[t._v("参数相同，如果在class中，这样写就很奇怪了，"),a("font",{staticStyle:{background:"yellow"}},[t._v("报错")])],1),t._v(" "),a("li",[t._v("参数不同，就是重载")])])])])]),t._v(" "),t._m(98),t._v(" "),a("li",[t._v("Overwrite\n"),a("ul",[a("li",[t._v("继承体系，不同作用域\n"),a("ul",[a("li",[t._v("情况1：参数不同，无论基类该函数是不是虚函数")]),t._v(" "),a("li",[t._v("情况2：参数相同，基类如果是『非虚函数』，那么就意味着在派生类中重新定义一个函数，"),a("font",{staticStyle:{background:"yellow"}},[t._v("也就是非多态")])],1)])])])])]),t._v(" "),t._m(99),t._v(" "),t._m(100),t._m(101),t._m(102),t._v(" "),t._m(103),t._m(104),t._v(" "),t._m(105),t._v(" "),t._m(106),t._v(" "),t._m(107),t._v(" "),t._m(108),t._v(" "),t._m(109),t._v(" "),t._m(110),t._m(111),t._v(" "),t._m(112),t._m(113),t._v(" "),t._m(114),t._v(" "),t._m(115),t._v(" "),a("ul",[t._m(116),t._v(" "),a("li",[a("font",{staticStyle:{background:"yellow"}},[t._v("动态绑定：符合某些条件就会做动态绑定，"),a("strong",[t._v("3个条件")])])],1)]),t._v(" "),t._m(117),t._m(118),t._v(" "),a("ul",[t._m(119),t._v(" "),a("li",[a("p",[t._v("牛客上配套习题："),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44172669&qid=15197#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("传送门"),a("OutboundLink")],1)])]),t._v(" "),t._m(120),t._v(" "),t._m(121),t._v(" "),t._m(122)]),t._v(" "),t._m(123),t._v(" "),t._m(124),t._v(" "),t._m(125),t._m(126),t._v(" "),t._m(127),t._v(" "),a("ul",[t._m(128),t._v(" "),a("li",[a("p",[a("font",{staticStyle:{background:"yellow"}},[t._v("虚析构函数：是为了解决基类的指针指向派生类对象，并且用『基类指针』删除派生类对象。")])],1)])]),t._v(" "),t._m(129),t._m(130),t._v(" "),t._m(131),t._m(132),t._m(133),t._v(" "),t._m(134),t._v(" "),a("ul",[t._m(135),t._v(" "),t._m(136),t._v(" "),a("li",[a("p",[t._v("牛客网"),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44308742&qid=180817#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("题目"),a("OutboundLink")],1),t._v("：")])])]),t._v(" "),t._m(137),t._m(138),t._v(" "),t._m(139),t._v(" "),a("ul",[a("li",[t._v("例题5")]),t._v(" "),a("li",[t._v("易错的题目"),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44470246&qid=44536#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("传送门"),a("OutboundLink")],1)])]),t._v(" "),t._m(140),t._m(141),t._v(" "),t._m(142),a("ul",[t._m(143),t._v(" "),a("li",[t._v("原因：\n"),a("ul",[t._m(144),t._v(" "),a("li",[a("font",{staticStyle:{background:"yellow"}},[t._v("这也是Ｃ++语言和其它语言Java, Python的一个显著区别")])],1),t._v(" "),t._m(145),t._v(" "),t._m(146),t._v(" "),a("li",[t._v("所以到了运行时，由于 test ()函数里面并没有任何需要解引用 pA 指针的代码，所以真实情况下也不会引发"),a("code",[t._v("segment fault")]),t._v("。\n"),a("ul",[a("li",[a("font",{staticStyle:{background:"yellow"}},[t._v("这里对成员函数的解析，和查找其对应的代码的工作都是在编译阶段完成而非运行时完成的，这就是所谓的静态绑定，也叫早绑定。正确理解C++的静态绑定可以理解一些特殊情况下C++的行为。『贼容易错』")])],1)])])])])]),t._v(" "),t._m(147),t._v(" "),a("ul",[t._m(148),t._v(" "),a("li",[a("p",[t._v("题目来源和"),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44470458&qid=1318#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("参考资料"),a("OutboundLink")],1)])])]),t._v(" "),t._m(149),t._m(150),t._v(" "),t._m(151),t._m(152),t._v(" "),t._m(153),t._v(" "),t._m(154),t._v(" "),t._m(155),t._v(" "),t._m(156),t._v(" "),a("p",[t._v("在多个派生类中如果动态分配了内存，虚析构函数可以分别释放。不然有可能造成内存泄漏。")]),t._v(" "),a("p",[t._v("虚析构函数是为了解决：基类的指针指向派生类对象，并用基类的指针删除派生类对象。")]),t._v(" "),t._m(157),t._v(" "),t._m(158),t._v(" "),a("blockquote",[a("p",[t._v("参考："),a("a",{attrs:{href:"https://www.huaweicloud.com/articles/ce10c517a25e175c5ab5d0c751c0319c.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("华为云博客：构造函数和析构函数中可以调用调用虚函数吗"),a("OutboundLink")],1)])]),t._v(" "),a("p",[t._v("１.　从语法上讲，调用完全没有问题。\n２.　但是从效果上看，往往不能达到需要的目的。")]),t._v(" "),t._m(159),t._v(" "),a("p",[t._v("为什么不能在析构和构造函数中调用呢,实际上这样做是不会报错的(试过了),但是不建议这样用")]),t._v(" "),t._m(160),t._v(" "),a("p",[t._v("因为父类对象会在子类之前进行构造，此时子类部分的数据成员还未初始化， 因此调用子类的虚函数是不安全的，故而C++不会进行动态联编。")]),t._v(" "),t._m(161),t._v(" "),t._m(162),t._v(" "),t._m(163),t._v(" "),t._m(164),t._v(" "),t._m(165),t._v(" "),t._m(166),t._v(" "),t._m(167),t._v(" "),t._m(168),t._m(169),t._v(" "),t._m(170),t._v(" "),t._m(171),t._m(172),t._v(" "),t._m(173),t._v(" "),a("blockquote",[a("p",[t._v("第2点，参考自用户讨论：@"),a("a",{attrs:{href:"https://www.nowcoder.com/profile/2887214",target:"_blank",rel:"noopener noreferrer"}},[t._v("牛客2887214号"),a("OutboundLink")],1)])]),t._v(" "),t._m(174),t._m(175),t._v(" "),t._m(176),t._v(" "),t._m(177),t._v(" "),t._m(178),t._v(" "),t._m(179),t._v(" "),t._m(180),t._v(" "),t._m(181),t._v(" "),t._m(182),t._v(" "),a("ul",[a("li",[t._v("《"),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=43575799&qid=67992",target:"_blank",rel:"noopener noreferrer"}},[t._v("C++Primer"),a("OutboundLink")],1),t._v("》")])]),t._v(" "),t._m(183),t._v(" "),a("ul",[a("li",[t._m(184),t._v(" "),a("ul",[t._m(185),t._v(" "),t._m(186),t._v(" "),a("li",[a("p",[t._v("参考：牛客网："),a("a",{attrs:{href:"https://www.nowcoder.com/test/question/done?tid=44308658&qid=14302#summary",target:"_blank",rel:"noopener noreferrer"}},[t._v("关于static用途说法正确的是"),a("OutboundLink")],1),t._v("？")])])])]),t._v(" "),t._m(187),t._v(" "),t._m(188),t._v(" "),t._m(189),t._v(" "),t._m(190)])])}),[function(){var t=this.$createElement,s=this._self._c||t;return s("h1",{attrs:{id:"c-98核心详解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#c-98核心详解"}},[this._v("#")]),this._v(" C++98核心详解")])},function(){var t=this.$createElement,s=this._self._c||t;return s("div",{staticClass:"language-txt line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[this._v('<font style="background:pink">\n')])]),this._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[this._v("1")]),s("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"📑-目录"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#📑-目录"}},[this._v("#")]),this._v(" 📑 目录")])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("学C++的利器：")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("this指针")]),this._v(" "),s("li",[this._v("虚函数表")]),this._v(" "),s("li",[this._v("内存管理")]),this._v(" "),s("li",[this._v("《STL源码剖析》")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"✅难点"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅难点"}},[this._v("#")]),this._v(" ✅难点")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("因为"),s("strong",[this._v("对于非虚成员函数，Ｃ++这门语言是静态绑定的")]),this._v("。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"✅c-和c定位纠偏"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅c-和c定位纠偏"}},[this._v("#")]),this._v(" ✅C++和C定位纠偏")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("C和C++从来就不是一个东西！")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("div",{staticClass:"language-txt line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[this._v("C++部分兼容C\n")])]),this._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[this._v("1")]),s("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[t._v("如 "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" a "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("malloc")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("16")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" 在C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("中要强制转换才行\n个人测试C99中有些特性在C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("中也没有\n如下面的代码： 定义一个二维变长数组作参数的函数。\n    gcc、clang可以编译运行通过。g"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("、clang"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("编译不通过。\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-c line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-c"}},[n("code",[t._v("C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("11")]),t._v("中没有的C99"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("C11特性\n    虽然在过去C或多或少可以看作是C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("的子集，但是C99标准增加了一些C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("没有的新特性\n下面列出了一些只有C99"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("C11中才有的特性"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\t\n\t指定初始化器"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t复合初始化器"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("Compound initializer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t受限指针"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v(" Restricted pointer"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("即，restric指针"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("变长数组"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t伸缩型数组成员"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t带可变数量参数的宏。\n\n注意\n以上所列只是在特定时期内的情况，随着时间的推移和C、C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("的不断发展，列表中的项会有所增减。\n    例如，C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("14")]),t._v("新增的一个特性就与『C99的变长数组』类似。\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("参考自：《C Primer Plus》P730")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"✅『oob』基于对象的程序设计"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅『oob』基于对象的程序设计"}},[this._v("#")]),this._v(" ✅『OOB』基于对象的程序设计")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_01-3加1对比"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_01-3加1对比"}},[this._v("#")]),this._v(" 01.3加1对比")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("class")]),t._v(" "),n("li",[t._v("struct")]),t._v(" "),n("li",[t._v("union")]),t._v(" "),n("li",[t._v("enum『枚举类型"),n("strong",[t._v("是1种基本类型")]),t._v("，不是1种构造类型，因为它不能再分解为任何其他基本类型，比如，"),n("code",[t._v("class")]),t._v("，"),n("code",[t._v("struct")]),t._v("，"),n("code",[t._v("union")]),t._v("』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_1-1-class"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-1-class"}},[this._v("#")]),this._v(" 1.1."),s("code",[this._v("class")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("、继承，默认是『"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("private")]),t._v("继承』\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("、内部可以放成员变量，成员函数，默认成员变量访问控制是：『"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("private")]),t._v("』\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v("、成员函数类：\n    有』构造函数\n    有』析构函数\n    有』虚函数\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_1-2-struct『c-中』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-2-struct『c-中』"}},[this._v("#")]),this._v(" 1.2."),s("code",[this._v("struct")]),this._v("『C++中』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("本质："),s("strong",[this._v("是一种class")])])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("、继承，默认是『"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v("继承』____\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("、内部可以放成员变量，成员函数，默认成员变量访问控制是：『"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v("』__\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v("、成员函数类：\n    有』构造函数\n    有』析构函数\n    有』虚函数\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("private")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("a")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("99")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"a="')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("this")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),t._v("a"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t\t"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("~")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"die AAA"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPoly")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*AAA******"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//struct B : private A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//下面的写法，等价于，struct B : public A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("  "),n("span",{pre:!0,attrs:{class:"token base-clause"}},[n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" b"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("b")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("-")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("888")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"b="')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("b"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("~")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"die BBB"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPoly")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"*BBBB******"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v('//因为加上了system("pause");所以需要下面这样挂掉B，才能知道B的析构函数被调用')]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tA one"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\tone"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\t\tB two"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\ttwo"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n\n\t\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" pointer"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" B"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\tpointer"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("myPoly")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("system")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"pause"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br"),n("span",{staticClass:"line-number"},[t._v("33")]),n("br"),n("span",{staticClass:"line-number"},[t._v("34")]),n("br"),n("span",{staticClass:"line-number"},[t._v("35")]),n("br"),n("span",{staticClass:"line-number"},[t._v("36")]),n("br"),n("span",{staticClass:"line-number"},[t._v("37")]),n("br"),n("span",{staticClass:"line-number"},[t._v("38")]),n("br"),n("span",{staticClass:"line-number"},[t._v("39")]),n("br"),n("span",{staticClass:"line-number"},[t._v("40")]),n("br"),n("span",{staticClass:"line-number"},[t._v("41")]),n("br"),n("span",{staticClass:"line-number"},[t._v("42")]),n("br"),n("span",{staticClass:"line-number"},[t._v("43")]),n("br"),n("span",{staticClass:"line-number"},[t._v("44")]),n("br"),n("span",{staticClass:"line-number"},[t._v("45")]),n("br"),n("span",{staticClass:"line-number"},[t._v("46")]),n("br"),n("span",{staticClass:"line-number"},[t._v("47")]),n("br"),n("span",{staticClass:"line-number"},[t._v("48")]),n("br"),n("span",{staticClass:"line-number"},[t._v("49")]),n("br"),n("span",{staticClass:"line-number"},[t._v("50")]),n("br"),n("span",{staticClass:"line-number"},[t._v("51")]),n("br"),n("span",{staticClass:"line-number"},[t._v("52")]),n("br"),n("span",{staticClass:"line-number"},[t._v("53")]),n("br"),n("span",{staticClass:"line-number"},[t._v("54")]),n("br"),n("span",{staticClass:"line-number"},[t._v("55")]),n("br"),n("span",{staticClass:"line-number"},[t._v("56")]),n("br"),n("span",{staticClass:"line-number"},[t._v("57")]),n("br"),n("span",{staticClass:"line-number"},[t._v("58")]),n("br"),n("span",{staticClass:"line-number"},[t._v("59")]),n("br"),n("span",{staticClass:"line-number"},[t._v("60")]),n("br"),n("span",{staticClass:"line-number"},[t._v("61")]),n("br"),n("span",{staticClass:"line-number"},[t._v("62")]),n("br"),n("span",{staticClass:"line-number"},[t._v("63")]),n("br"),n("span",{staticClass:"line-number"},[t._v("64")]),n("br"),n("span",{staticClass:"line-number"},[t._v("65")]),n("br"),n("span",{staticClass:"line-number"},[t._v("66")]),n("br"),n("span",{staticClass:"line-number"},[t._v("67")]),n("br"),n("span",{staticClass:"line-number"},[t._v("68")]),n("br"),n("span",{staticClass:"line-number"},[t._v("69")]),n("br"),n("span",{staticClass:"line-number"},[t._v("70")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_1-3-union『c-中』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-3-union『c-中』"}},[this._v("#")]),this._v(" 1.3."),s("code",[this._v("union")]),this._v("『C++中』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("本质：它是一种"),s("strong",[this._v("特殊的类")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("参考《后台开发》")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("、继承：继承自别人"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("/")]),t._v("能给别人继承都『不可以』______\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("、内部可以放成员变量，成员函数，默认成员变量访问控制是：『"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v("』__\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v("、成员函数类：\n    有』构造函数\n    有』析构函数\n    不可以有』虚函数______\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_1-4-enum『只有它不是特殊的类』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-4-enum『只有它不是特殊的类』"}},[this._v("#")]),this._v(" 1.4."),s("code",[this._v("enum")]),this._v("『只有它不是特殊的类』")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("blockquote",[n("p",[t._v("枚举类型"),n("strong",[t._v("是1种基本类型")]),t._v("，不是1种构造类型，因为它不能再分解为任何其他基本类型『比如，"),n("code",[t._v("class")]),t._v("，"),n("code",[t._v("struct")]),t._v("，"),n("code",[t._v("union")]),t._v("』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_02-类的『成员变量』和『非成员变量』⭐️"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_02-类的『成员变量』和『非成员变量』⭐️"}},[this._v("#")]),this._v(" 02.类的『成员变量』和『非成员变量』⭐️")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_2-1-成员变量"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-1-成员变量"}},[this._v("#")]),this._v(" 2.1.成员变量")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[s("strong",[this._v("书中记载")]),this._v("：")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("nonstatic member 非静态成员\n"),s("ul",[s("li",[this._v("普通数据成员")]),this._v(" "),s("li",[this._v("const数据成员")])])]),this._v(" "),s("li",[this._v("static member 静态成员")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[s("strong",[this._v("static成员变量")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("c++的一个类中『"),s("strong",[this._v("声明")]),this._v("』一个static成员变量，static是加了访问控制的全局变量，不被继承")]),this._v(" "),s("li",[this._v("类和子类对象，static变量占有一份内存")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("重点理解："),s("strong",[this._v("静态成员变量的初始化一定要在『类外』")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("原因： 因为静态成员变量本身在main函数未开始时已经存在。不要让成员变量的初始化依赖于对象。不用对象，难到就不能用这一变量了吗？如果将初始化放在类内。那么"),s("strong",[this._v("当不声明对象时")]),this._v("，无法使用这一静态变量。编译器报错为‘undeclared identifier’")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-txt line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("类中的声明和定义辨析：（重点、难点）\n笔者的看法是：\n1、逻辑上说明是一起，只能表示可以『声明』在一起。（声明的门槛很低）\n2、具体内存在哪分配，这个决定『能不能在类内』进行『定义』\n\n比如：\n1、友元函数在『类内』声明，不能在『类内』定义，能在『类外』定义\n2、static成员变量在『类内』声明，不能在『类内』定义，能在『类外』定义\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[s("strong",[this._v("static和非static特点")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("静态成员存在于"),s("strong",[this._v("内存")]),this._v("，非静态成员需要实例化才会分配内存（注意，也就是在虚拟内存空间中，表示的是.bss和.data段中）")]),this._v(" "),s("li",[this._v("非静态成员的生存期决定于该类的生存期，而静态成员生存期则与程序生命期相同")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_2-2-非成员变量"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-2-非成员变量"}},[this._v("#")]),this._v(" 2.2.非成员变量")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_03-类的『成员函数』和『非成员函数』⭐️"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_03-类的『成员函数』和『非成员函数』⭐️"}},[this._v("#")]),this._v(" 03.类的『成员函数』和『非成员函数』⭐️")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("说明：成员函数的分类，需要考虑排序组合，"),s("strong",[this._v("是很多，很复杂")]),this._v("的，不然就只能一个一个维度去分类。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-1-成员函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-1-成员函数"}},[this._v("#")]),this._v(" 3.1.成员函数")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("到底什么是成员函数？")]),t._v(" "),n("li",[t._v("类的成员函数：是定义为"),n("strong",[t._v("类的一部分")]),t._v("的函数，有时也被称为方法。（C++primer第5版，P20）")]),t._v(" "),n("li",[t._v("各类函数中：构造函数、析构函数、拷贝初始化构造函数等是类的成员函数。")]),t._v(" "),n("li",[t._v("成员函数分下面3类（应该说是2类，纯虚函数属于虚函数的子集的话）")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-txt line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("1、非虚函数（non-virtual 函数）：\n你『不希望』派生类（derived class）重新定义 (override, 复写) 它.\n\n\n\n2、虚函数（virtual 函數）：\n你希望 derived class 重新定义 (override, 复写) 它，且你对它已有『默认』定义。\n3、纯虚函数（pure virtual 函數）：\n你希望 derived class 『一定』要重新定义 (override 复写)\n它，你对它沒有默认定义。\n\nPS：我们把不是纯的虚函数的虚函数叫作（impure virtual函数）\nPS：在语法上，我们只要在任何一个函数前面加上virtual这样一个关键字，它就成为一个虚函数。\n数据可以被继承下来，就是占它用了内存。\n函数的继承如何理解？但是不应该从内存角度理解，函数的继承，继承的是调用权利\n\nPS：其实纯虚函数是可以有定义的！！\n> 出处：《C++Primer》中文版第五版541页第22行。\n我们可以为纯虚函数提供定义，不过函数体『必须定义在类的外部』。若定义在类的内部，会出现错误：pure-specifier on function-definition。\n》 虚函数是可以定义『在类的内部的』，外部也可以！\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("参考自：侯捷")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[s("strong",[this._v("override")]),this._v("这个术语，在这个主题不能随便用！！")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("这个术语，"),s("strong",[this._v("一定是用在『虚函数』被重新定义，才能够叫（override）")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[s("strong",[this._v("纯虚函数")]),this._v("：只提供一个"),s("strong",[this._v("接口")]),this._v("，具体实现方法需要"),s("strong",[this._v("派生类")]),this._v("自己去实现，纯虚函数本身不可以有实现")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[s("strong",[this._v("非虚函数")]),this._v("：提供接口，并且强制"),s("strong",[this._v("实现")]),this._v("方法")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("根据《"),s("strong",[this._v("深度探索C++对象模型")]),this._v("》一书所说：")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("原始的“C with Classes”只支持，"),s("strong",[this._v("（Nonstatic member function）非静态成员函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[s("strong",[this._v("（Virtual function）虚函数")]),this._v("，是在20世纪80年代中期加入进来的。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[s("strong",[this._v("（Static member function）静态成员函数")]),this._v("是最后被引入的一种函数类型!")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("1、static member function")]),t._v(" "),n("li",[t._v("2、nonstatic member function\n"),n("ul",[n("li",[t._v("1、普通的成员函数")]),t._v(" "),n("li",[t._v("2、const成员函数")])])]),t._v(" "),n("li",[t._v("3、virtual member function")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("成员函数中"),s("strong",[this._v("易错")]),this._v("：")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("由于成员函数中的const成员函数，const"),s("strong",[this._v("实际")]),this._v("上修饰的是"),s("strong",[this._v("this指针")]),this._v("。")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//这行没错")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("static")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" maxn"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1000")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//修饰变量，这行却没错")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("static")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("9")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n  \n    \t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//下面会出错，[Error] static member function 'static void A::demo()' cannot have cv-qualifier")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("static")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" \n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("a"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("::")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("demo")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-2-非成员函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-非成员函数"}},[this._v("#")]),this._v(" 3.2.非成员函数")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h4",{attrs:{id:"_3-2-1-友元函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-1-友元函数"}},[this._v("#")]),this._v(" 3.2.1.友元函数")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("1、友元函数的『"),s("strong",[this._v("声明")]),this._v("』可以放在类"),s("strong",[this._v("声明")]),this._v("的任何地方，不受访问限定关键字private、protected、public的限制")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("2、尽管友元函数的"),s("strong",[this._v("原型")]),this._v("有在"),s("strong",[this._v("类的定义")]),this._v("中出现过，但是"),s("strong",[this._v("友元函数并不是成员函数")]),this._v("。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("3、友元是一种"),s("strong",[this._v("定义在类外部")]),this._v("的普通函数（友元函数既可以在类的内部，也可以在类的外部定义《"),s("strong",[this._v("C++primer")]),this._v("》中说了），但它需要在类体内进行"),s("strong",[this._v("说明『声明』")]),this._v("，为了与该类的成员函数加以区别，在说明时前面加以关键字friend")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h4",{attrs:{id:"_3-2-2-友元"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-2-友元"}},[this._v("#")]),this._v(" 3.2.2.友元")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("一个基类的声明中有纯虚函数，该基类派生类一定不再是抽象类（错误）")]),this._v(" "),s("li",[this._v("如果在派生类中没有对所有纯虚函数进行定义，则此派生类仍然是抽象类，不能用来定义对象。所以A错.")]),this._v(" "),s("li",[this._v("构造函数不能被覆盖")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_04-big-three讲解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_04-big-three讲解"}},[this._v("#")]),this._v(" 04."),s("code",[this._v("Big Three")]),this._v("讲解")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("参考自：侯捷的说法，好像来自《C++ Primer》")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-1-构造函数详解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-构造函数详解"}},[this._v("#")]),this._v(" 4.1.构造函数详解")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h4",{attrs:{id:"_1-普通ctor（普通构造函数）"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-普通ctor（普通构造函数）"}},[this._v("#")]),this._v(" 1.普通ctor（普通构造函数）")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("1、无参的普通构造函数")]),this._v(" "),s("li",[this._v("2、有参的普通构造函数\n"),s("ul",[s("li",[this._v("（1）类型转换构造函数：只有1个参数的普通构造函数一般都可以称作『类型转换构造函数』")]),this._v(" "),s("li",[this._v("（2）其他有参的普通构造函数")])])])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//无参的『普通构造函数』")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//有参的『普通构造函数』，并且由于只有1个参数，也叫『类型转换构造函数』")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" i"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n          \tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Int Constructor calles"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("  \n        "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    \t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v(" a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n            cout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Copy ctor"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n            "),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//拷贝构造函数，原因是参数是『本类类型的引用』")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    \n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h4",{attrs:{id:"_2-copy-ctor"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-copy-ctor"}},[this._v("#")]),this._v(" 2.copy ctor")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("又称；复制构造函数/拷贝构造函数/拷贝初始化构造函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("1、默认的『copy ctor』")]),this._v(" "),s("li",[this._v("2、如果你自行编写了新的copy ctor，那么默认的copy ctor就不存在了")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[t._v("Demo "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("c2")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("c1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//会调用copy ctor，初始化")]),t._v("\nDemo c2"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("c1"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//会调用copy ctor，注意是初始化，不是赋值！")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-2-析构函数详解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-析构函数详解"}},[this._v("#")]),this._v(" 4.2.析构函数详解")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h4",{attrs:{id:"_4-2-1-有无virtual"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-1-有无virtual"}},[this._v("#")]),this._v(" 4.2.1.有无virtual")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[s("strong",[this._v("没有")]),this._v("virtual的析构函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("又称："),s("strong",[this._v("一般")]),this._v("的析构函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[s("strong",[this._v("有")]),this._v("virtual的析构函数")]),this._v(" "),s("li",[this._v("析构时区别 "),s("code",[this._v("delete")]),this._v(" 和 "),s("code",[this._v("delete[]")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-2-2-是否私有"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-2-是否私有"}},[this._v("#")]),this._v(" 4.2.2.是否私有")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("在C++中，为了让某个类"),s("strong",[this._v("只能通过new来创建")]),this._v("（即如果直接创建对象，编译器将报错）")]),this._v(" "),s("li",[this._v("应该将"),s("strong",[this._v("析构函数设为私有")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_05-访问属性"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_05-访问属性"}},[this._v("#")]),this._v(" 05.访问属性")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_5-1-内部访问和对象访问"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_5-1-内部访问和对象访问"}},[this._v("#")]),this._v(" 5.1.内部访问和对象访问")])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("参考牛客的答案：")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_06-namespace命名空间"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_06-namespace命名空间"}},[this._v("#")]),this._v(" 06."),s("code",[this._v("namespace")]),this._v("命名空间")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("namespace，是指标识符的各种可见范围")]),t._v(" "),n("li",[t._v("C++标准程序库中的所有标识符都被定义于一个名为std的namespace中。\n"),n("ul",[n("li",[t._v("一 ："),n("code",[t._v("<iostream>")]),t._v("和<iostream.h>格式不一样，前者没有后缀，实际上，在你的编译器include文件夹里面可以看到，二者是两个文件，打开文件就会发现，里面的代码是不一样的。")]),t._v(" "),n("li",[t._v("后缀为.h的头文件c++标准已经明确提出不支持了，早些的实现将标准库功能定义在"),n("strong",[t._v("全局空间")]),t._v("里，声明在带.h后缀的头文件里，c++标准为了和C区别开，也为了正确使用命名空间，规定头文件不使用后缀.h。 因此。")]),t._v(" "),n("li",[t._v("1、命名空间主要是将全局空间、『划分为更加小块的全局空间』")])])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"✅『oop』面向对象的程序设计"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅『oop』面向对象的程序设计"}},[this._v("#")]),this._v(" ✅『OOP』面向对象的程序设计")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("面向对象的三大基本特征：封装、继承、多态")]),this._v(" "),s("li",[this._v("面向对象的五大基本原则：")]),this._v(" "),s("li",[this._v("单一职责原则、开放封闭原则、里氏替换原则、依赖倒置原则、接口隔离原则")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_1-1-类型转换函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_1-1-类型转换函数"}},[this._v("#")]),this._v(" 1.1.类型转换函数")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[n("p",[t._v("带非默认参数的构造函数可以把基本类型数据转换成类类型对象。")])]),t._v(" "),n("li",[n("p",[t._v("『类型转换函数』可以把类类型对象转换为其他指定类型对象。")])]),t._v(" "),n("li",[n("p",[t._v("『类型转换函数』只能定义为一个类的成员函数，"),n("strong",[t._v("不能")]),t._v("定义为类的"),n("strong",[t._v("友元函数。")])])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_01-辨析overload、override、overwrite⭐️"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_01-辨析overload、override、overwrite⭐️"}},[this._v("#")]),this._v(" 01.辨析Overload、Override、Overwrite⭐️")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[s("strong",[this._v("重载(Overload)")]),this._v("：\n"),s("ul",[s("li",[s("strong",[this._v("在同一作用域内")]),this._v("，函数名相同，函数的参数个数、参数类型或参数顺序三者中必须至少有一种不同。函数返回值的类型可以相同，也可以不相同。比如：发生在一个类内部。")])])])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("blockquote",[n("p",[t._v("郑莉：C++允许功能相近的函数在"),n("strong",[t._v("相同的作用域内")]),t._v("以相同函数名声明。从而形成重载。方便使用记忆。")]),t._v(" "),n("p",[t._v("《"),n("strong",[t._v("C++ Primer")]),t._v("》P206，如果“"),n("strong",[t._v("同一作用域")]),t._v("”内的几个函数名字相同但“形参列表”不同，我们称之为重载（"),n("strong",[t._v("overloaded")]),t._v("）函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("子类重新定义父类虚函数的方法叫做覆写")]),this._v(" "),s("li",[this._v("多态是为了"),s("strong",[this._v("接口")]),this._v("重用，封装和继承是为了代码重用")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"✅区分overload、overwrite和override"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅区分overload、overwrite和override"}},[this._v("#")]),this._v(" ✅区分Overload、Overwrite和Override")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("注意，由于这3个词的翻译很尴尬，众说纷纭，我们直接考虑单词来")]),this._v(" "),s("li",[this._v("『记忆版』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("都是在函数名相同的时候，都不考虑返回值的情况下，我们讨论下面3组")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("Override\n"),s("ul",[s("li",[this._v("继承体系，不同作用域")]),this._v(" "),s("li",[this._v("基类该函数是虚函数")]),this._v(" "),s("li",[this._v("参数相同")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"成员函数加和不加virtual算不算重载？"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#成员函数加和不加virtual算不算重载？"}},[this._v("#")]),this._v(" 成员函数加和不加virtual算不算重载？")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("val")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"non-virtual=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("val"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"virtual=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" val"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("private")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" val"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token base-clause"}},[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"BBB"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    A a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br"),n("span",{staticClass:"line-number"},[t._v("33")]),n("br"),n("span",{staticClass:"line-number"},[t._v("34")]),n("br"),n("span",{staticClass:"line-number"},[t._v("35")]),n("br"),n("span",{staticClass:"line-number"},[t._v("36")]),n("br"),n("span",{staticClass:"line-number"},[t._v("37")]),n("br"),n("span",{staticClass:"line-number"},[t._v("38")]),n("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-bash line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-bash"}},[n("code",[n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("root@CentosLinux apue"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("# g++ demo.cpp ")]),t._v("\ndemo.cpp:15:18: error: ‘virtual void A::test"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("’ cannot be overloaded\n     virtual void test"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n                  ^\ndemo.cpp:11:10: error: with ‘void A::test"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("’\n     void test"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("如上，"),s("code",[this._v("virtual void A::test()")]),this._v("不能被重载")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" num"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("9")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"global=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" num"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("val")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"virtual=%d\\n"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" val"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("private")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" val"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    A a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_02-多态与虚函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_02-多态与虚函数"}},[this._v("#")]),this._v(" 02.多态与虚函数")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_2-1-static变量的说明"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-1-static变量的说明"}},[this._v("#")]),this._v(" 2.1."),s("code",[this._v("static")]),this._v("变量的说明")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("c++的一个类中声明一个"),s("strong",[this._v("static成员变量")]),this._v("，下面描述正确的是")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("static是加了访问控制的全局变量，『"),s("strong",[this._v("不被继承")]),this._v("』，类和子类对象，static变量占有一份内存")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_2-2-虚函数相关"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-2-虚函数相关"}},[this._v("#")]),this._v(" 2.2.虚函数相关")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("1、（static）静态函数不可以是虚函数『虚成员函数不可能是static 成员函数』")]),this._v(" "),s("li",[this._v("2、（inline）虚函数可以声明为inline，但是编译器不会将其作为inline函数处理『有的选择题故意为难，但是其实虚函数是可以声明为inline的，但是分情况』』")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("a")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("inline")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n尽管以上写法是没有语法错误的，并且可以执行，但其实test函数已经不是内联函数了，因为"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("inline")]),t._v("只是对编译器的一个建议而已。\n搞清本质就好。\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_2-2-虚函数能不能inline"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_2-2-虚函数能不能inline"}},[this._v("#")]),this._v(" 2.2.虚函数能不能inline")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-txt line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("Q:虚函数不能内联，但是语法不出错？\n\nA:不是的，虚函数在『『没有表现多态的时候』』是可以内联的，表现多态的时候不能\n\n『没有表现多态的时候』:内联只是对编译器的一种请求，是否真正内联要看编译器的处理，虚函数是可以内联的，但是编译器不会响应内联请求，即他会忽略内联说明，将其当做普通虚函数处理。\n\n有说法说：\n虚函数不可以内联，因为虚函数是在运行期的时候确定具体调用的函数，内联是在编译期的时候进行代码展开，两者冲突，所以没有一起使用的做法。『『这是不严谨的』』\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_03-『多态神器』-多态3条件"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_03-『多态神器』-多态3条件"}},[this._v("#")]),this._v(" 03.『多态神器』-多态3条件")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("『『"),s("code",[this._v("动态绑定3条件")]),this._v("』』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("C++编译器，看到一个函数调用，他有2个考量，静态还是动态绑定：")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("静态被编译成："),s("code",[this._v("call")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("、通过指针来调用『注意，引用显然也是的，因为底层也是指针』\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("、这个指针是向上转型up cast了。『比如，派生类赋值给基类指针，基类指针调用』\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v("、调用虚函数\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-1-条件1和条件2❎『非多态』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-1-条件1和条件2❎『非多态』"}},[this._v("#")]),this._v(" 3.1.条件1和条件2❎『非多态』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("例题1.")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("题解：")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("这一题中，最后一个c，是相当于强制类型转换，『或许叫：向下转型？？』，然后没有通过指针来调用")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("用牛油的一个解释：动态绑定（多态）只有在指针和引用时才有效，其他情况下无效。")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-2-条件3❎『非多态』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-2-条件3❎『非多态』"}},[this._v("#")]),this._v(" 3.2.条件3❎『非多态』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("例题2.")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mytest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"AAA"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t\t\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token base-clause"}},[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mytest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tcout"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"BBB"')]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v("endl"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\t\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\n\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v(" p"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" B"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\tp"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("mytest")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//输出的是AAA")]),t._v("\n    \n\t\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" \n\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("本题不是动态绑定原因分析：")]),t._v(" "),n("li",[t._v("1、通过指针来调用『注意，引用显然也是的，因为底层也是指针』\n"),n("ul",[n("li",[t._v("满足，用了"),n("code",[t._v("p->mytest();")])])])]),t._v(" "),n("li",[t._v("2、这个指针是向上转型up cast了『比如，派生类赋值给基类指针，基类指针调用』\n"),n("ul",[n("li",[t._v("满足，A是B的基类")])])]),t._v(" "),n("li",[t._v("3、调用虚函数❎不满足\n"),n("ul",[n("li",[t._v("因为p指针是A类型的，但是在classA中该函数还不是『虚函数』，所以想走虚函数指针——虚函数表的路径走不通。")])])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-3-虚析构函数"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-3-虚析构函数"}},[this._v("#")]),this._v(" 3.3.虚析构函数")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("例题3")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<iostream>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"1"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"2"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("~")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"3"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token base-clause"}},[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"4"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("B "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),t._v("b"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"5"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("~")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n        cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"6"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n    A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pa "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" pa"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n    "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//输出是：1 4 6 3")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br"),n("span",{staticClass:"line-number"},[t._v("33")]),n("br"),n("span",{staticClass:"line-number"},[t._v("34")]),n("br"),n("span",{staticClass:"line-number"},[t._v("35")]),n("br"),n("span",{staticClass:"line-number"},[t._v("36")]),n("br"),n("span",{staticClass:"line-number"},[t._v("37")]),n("br"),n("span",{staticClass:"line-number"},[t._v("38")]),n("br"),n("span",{staticClass:"line-number"},[t._v("39")]),n("br"),n("span",{staticClass:"line-number"},[t._v("40")]),n("br"),n("span",{staticClass:"line-number"},[t._v("41")]),n("br"),n("span",{staticClass:"line-number"},[t._v("42")]),n("br"),n("span",{staticClass:"line-number"},[t._v("43")]),n("br")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[n("p",[t._v("考察的是对继承体系中的构造和析构函数调用顺序的理解。")])]),t._v(" "),n("li",[n("p",[t._v("在调用new B()的时候，因为B继承A，所以会首先调用其父类的构造函数，输出1")])]),t._v(" "),n("li",[n("p",[t._v("然后调用自己的构造函数，输出4")])]),t._v(" "),n("li",[n("p",[t._v("//析构的时候，是会调用的")])]),t._v(" "),n("li",[n("p",[t._v("对比，下面，如果去除掉A的析构函数的，虚函数")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("div",{staticClass:"language-cpp line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-cpp"}},[s("code",[s("span",{pre:!0,attrs:{class:"token operator"}},[this._v("~")]),s("span",{pre:!0,attrs:{class:"token function"}},[this._v("A")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[this._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[this._v(")")]),this._v("\n")])]),this._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[this._v("1")]),s("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("div",{staticClass:"language-txt line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[this._v("输出为：1 4 3\n")])]),this._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[this._v("1")]),s("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("原因：\n"),s("ul",[s("li",[s("strong",[this._v("静态绑定，this指针直接调用了A的析构")]),this._v("，B的没有。")]),this._v(" "),s("li",[this._v("很显然，有的时候，会出问题。")])])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-4-『添加作用域的调用』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-4-『添加作用域的调用』"}},[this._v("#")]),this._v(" 3.4.『添加作用域的调用』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("例题4")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("多态情况下，不调用多态")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-txt line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-text"}},[n("code",[t._v("类B是类A的公有派生类，类A和类B中都定义了虚函数func(),p是一个指向类A对象的指针，则p->A::func()将（）？\n\n正确答案: C   你的答案: C (正确)\n\nA\t调用类B中函数func()\nB\t即调用类A中函数，也调用类B中的函数\nC\t调用类A中函数func()\nD\t根据p所指的对象类型而确定调用类A中或类B中的函数func()\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("不论指针p是属于类A还是类B，也不论指针p指向的对象属于类A还是类B(当然，不能用类B的指针指向类A的对象)，"),s("strong",[this._v("因为加了作用域说明符"),s("code",[this._v("A::")]),this._v("，因此都只会调用类A的函数")]),this._v("。")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-5-静态绑定的核心理解『易错难点』⭐️"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-5-静态绑定的核心理解『易错难点』⭐️"}},[this._v("#")]),this._v(" 3.5.静态绑定的核心理解『易错难点』⭐️")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" \n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" \n\t\t\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("printf")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"test A"')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" \n\t\t"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("pA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token constant"}},[t._v("NULL")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//注意『这是个幌子』")]),t._v("\n\tpA"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("test")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("有4个选项")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("div",{staticClass:"language-txt line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[this._v('问你选什么？\nA    编译出错\nB    程序运行奔溃\nC    输出"test A"\nD    输出乱码\n')])]),this._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[this._v("1")]),s("br"),s("span",{staticClass:"line-number"},[this._v("2")]),s("br"),s("span",{staticClass:"line-number"},[this._v("3")]),s("br"),s("span",{staticClass:"line-number"},[this._v("4")]),s("br"),s("span",{staticClass:"line-number"},[this._v("5")]),s("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("答案："),s("strong",[this._v('输出"test A"')])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("因为"),s("strong",[this._v("对于非虚成员函数，Ｃ++这门语言是静态绑定的")]),this._v("。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("code",[this._v("//pA->test();")]),this._v("这语句的意图是：调用对象 pA 的 test 成员函数。如果这句话在Java或Python等动态绑定的语言之中，编译器生成的代码大概是：\n"),s("ul",[s("li",[this._v("找到 pA 的 test 成员函数，调用它。（注意，这里的找到是程序运行的时候才找的，这也是所谓动态绑定的含义：运行时才绑定这个函数名与其对应的实际代码。有些地方也称这种机制为迟绑定，晚绑定。）")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[this._v("但是对于C++。为了保证程序的运行时效率，Ｃ++的设计者认为凡是编译时能确定的事情，就不要拖到运行时再查找了。所以C++的编译器看到这句话会这么干：\n"),s("ul",[s("li",[this._v("１：查找 pA 的类型，发现它有一个非虚的成员函数叫 test 。（编译器干的）")]),this._v(" "),s("li",[this._v("２：找到了，在这里生成一个函数调用，直接调"),s("code",[this._v("A:: test ( pA )")]),this._v("。")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_3-6-const对象"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_3-6-const对象"}},[this._v("#")]),this._v(" 3.6.const对象")])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("例题6")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token macro property"}},[n("span",{pre:!0,attrs:{class:"token directive-hash"}},[t._v("#")]),n("span",{pre:!0,attrs:{class:"token directive keyword"}},[t._v("include")]),n("span",{pre:!0,attrs:{class:"token string"}},[t._v("<bits/stdc++.h>")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("using")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("namespace")]),t._v(" std"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("virtual")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A::f() "')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A::f() const "')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("class")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token base-clause"}},[n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")])]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("public")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"B::f() "')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v(" cout "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<<")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"B::f() const "')]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("void")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("g")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" A "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("a"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\ta"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("int")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tA "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("p "),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\tp"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//多态")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("g")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("p"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//先转换为const指针，由于只能调用const函数，所以不是多态了")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("delete")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("p"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\t"),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("return")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//输出")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//B::f() A::f() const")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//输出前面是因为多态")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//输出后面是因为不是多态！！！（注意）")]),t._v("\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br"),n("span",{staticClass:"line-number"},[t._v("7")]),n("br"),n("span",{staticClass:"line-number"},[t._v("8")]),n("br"),n("span",{staticClass:"line-number"},[t._v("9")]),n("br"),n("span",{staticClass:"line-number"},[t._v("10")]),n("br"),n("span",{staticClass:"line-number"},[t._v("11")]),n("br"),n("span",{staticClass:"line-number"},[t._v("12")]),n("br"),n("span",{staticClass:"line-number"},[t._v("13")]),n("br"),n("span",{staticClass:"line-number"},[t._v("14")]),n("br"),n("span",{staticClass:"line-number"},[t._v("15")]),n("br"),n("span",{staticClass:"line-number"},[t._v("16")]),n("br"),n("span",{staticClass:"line-number"},[t._v("17")]),n("br"),n("span",{staticClass:"line-number"},[t._v("18")]),n("br"),n("span",{staticClass:"line-number"},[t._v("19")]),n("br"),n("span",{staticClass:"line-number"},[t._v("20")]),n("br"),n("span",{staticClass:"line-number"},[t._v("21")]),n("br"),n("span",{staticClass:"line-number"},[t._v("22")]),n("br"),n("span",{staticClass:"line-number"},[t._v("23")]),n("br"),n("span",{staticClass:"line-number"},[t._v("24")]),n("br"),n("span",{staticClass:"line-number"},[t._v("25")]),n("br"),n("span",{staticClass:"line-number"},[t._v("26")]),n("br"),n("span",{staticClass:"line-number"},[t._v("27")]),n("br"),n("span",{staticClass:"line-number"},[t._v("28")]),n("br"),n("span",{staticClass:"line-number"},[t._v("29")]),n("br"),n("span",{staticClass:"line-number"},[t._v("30")]),n("br"),n("span",{staticClass:"line-number"},[t._v("31")]),n("br"),n("span",{staticClass:"line-number"},[t._v("32")]),n("br"),n("span",{staticClass:"line-number"},[t._v("33")]),n("br"),n("span",{staticClass:"line-number"},[t._v("34")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("解释原因")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[t._v("由于"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("在基类中声明为虚的，则p"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("根据『对象类型』"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("B"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("调用"),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("::")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("，此时编译器对虚方法使用动态联编，输出"),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("B")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("::")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("。\n    \n由于"),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v("在基类中未声明为虚的，故p"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" 『根据指针类型』"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("A"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("调用"),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("::")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v("，此时编译器对非虚方法使用静态联编，输出"),n("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("A")]),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("::")]),n("span",{pre:!0,attrs:{class:"token function"}},[t._v("f")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),n("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v("。\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"_04-构造函数（ctor）和析构函数（dtor）相关⭐️"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_04-构造函数（ctor）和析构函数（dtor）相关⭐️"}},[this._v("#")]),this._v(" 04.构造函数（ctor）和析构函数（dtor）相关⭐️")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-1-c-构造函数和析构函数可以是虚函数嘛？"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-c-构造函数和析构函数可以是虚函数嘛？"}},[this._v("#")]),this._v(" 4.1.C++ 构造函数和析构函数可以是虚函数嘛？")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("构造函数"),s("strong",[this._v("不可以")]),this._v("是虚函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("因为虚函数只有和类的对象结合才能体现多态性，"),s("strong",[this._v("构造函数被调用时，类对象还没有完成建立")]),this._v("，所以无意义。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("析构函数"),s("strong",[this._v("可以且常常")]),this._v("是虚函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("参考自：《面向对象技术与Visual C++学习指导》，甘玲， 邱劲，张璞")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-2-构造函数中调用虚函数会怎么样？"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-构造函数中调用虚函数会怎么样？"}},[this._v("#")]),this._v(" 4.2.构造函数中调用虚函数会怎么样？")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("《Effective C++ 》条款9：永远不要在构造函数或析构函数中调用虚函数")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("书上,其实就是作者告诉你"),s("strong",[this._v("构造函数和析构函数中调用虚函数不会呈现出多态")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-3-析构函数中调用虚函数会怎么样？"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-析构函数中调用虚函数会怎么样？"}},[this._v("#")]),this._v(" 4.3.析构函数中调用虚函数会怎么样？")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("不要在析构函数中调用虚函数的原因：析构函数是用来销毁一个对象的，在销毁一个对象时，先调用子类的析构函数，然后再调用基类的析构函数。所以"),s("strong",[this._v("在调用基类的析构函数时，派生类对象的数据成员已经“销毁”，这个时再调用子类的虚函数已经没有意义了")]),this._v("。")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"⭐️04-『运算符重载』详解"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#⭐️04-『运算符重载』详解"}},[this._v("#")]),this._v(" ⭐️04.『运算符重载』详解")])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("（本质还是函数重载）")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-1-重载的2种函数类型"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-1-重载的2种函数类型"}},[this._v("#")]),this._v(" 4.1.重载的2种函数类型")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("1、成员函数")]),this._v(" "),s("li",[this._v("2、友元函数『属于，非成员函数』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("易错：有的运算符，只能重载为『成员函数』")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" \t\t\t\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\t\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//重载，下标运算符，比如重载后，返回当前vetor中的元素，需要this指针，而非成员函数是没有this指针的233")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),n("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\t\t\t"),n("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//重载，函数调用运算符，")]),t._v("\n"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("->")]),t._v("\n上面"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v("个，『只能』通过成员函数进行重载\n我的理解，备注如上\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-2-可以重载，但建议不要重载的运算符"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-2-可以重载，但建议不要重载的运算符"}},[this._v("#")]),this._v(" 4.2.可以重载，但建议不要重载的运算符")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[s("code",[this._v("&&")]),this._v("和"),s("code",[this._v("||")]),this._v("很建议不要重载『会出点问题』")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("、因为，重载运算符，也就意味着靠函数重载来完成，操作数会作为『函数参数，传递』\n"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("、C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("的『函数参数都会被求值，无法实现（短路规则）』\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_4-3-不能重载的5个运算符记忆"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_4-3-不能重载的5个运算符记忆"}},[this._v("#")]),this._v(" 4.3.不能重载的5个运算符记忆")])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[n("p",[t._v("百度招聘考过。")])]),t._v(" "),n("li",[n("p",[t._v("1、第1个，也是我们常常忘记是运算符的"),n("code",[t._v("sizeof")])])]),t._v(" "),n("li",[n("p",[t._v("2、其他4个，记住只要挂"),n("code",[t._v(".")]),t._v("的运算符"),n("strong",[t._v("均不能被重载")])])])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("div",{staticClass:"language-cpp line-numbers-mode"},[n("pre",{pre:!0,attrs:{class:"language-cpp"}},[n("code",[t._v("C"),n("span",{pre:!0,attrs:{class:"token operator"}},[t._v("++")]),t._v("不能重载的总共五个：\n（"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),t._v("）"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"."')]),t._v("（类成员访问运算符） \n（"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("2")]),t._v("）"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('" .*"')]),t._v("（类成员指针访问运算符） \n（"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("3")]),t._v("）"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"::"')]),t._v("（域运算符） \n（"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("4")]),t._v("）"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('"siezof"')]),t._v("（长度运算符） \n（"),n("span",{pre:!0,attrs:{class:"token number"}},[t._v("5")]),t._v("）"),n("span",{pre:!0,attrs:{class:"token string"}},[t._v('" ?:"')]),t._v("（条件运算符）\n")])]),t._v(" "),n("div",{staticClass:"line-numbers-wrapper"},[n("span",{staticClass:"line-number"},[t._v("1")]),n("br"),n("span",{staticClass:"line-number"},[t._v("2")]),n("br"),n("span",{staticClass:"line-number"},[t._v("3")]),n("br"),n("span",{staticClass:"line-number"},[t._v("4")]),n("br"),n("span",{staticClass:"line-number"},[t._v("5")]),n("br"),n("span",{staticClass:"line-number"},[t._v("6")]),n("br")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"⭐️05-c-中『栈』和『堆』"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#⭐️05-c-中『栈』和『堆』"}},[this._v("#")]),this._v(" ⭐️05.C++中『栈』和『堆』")])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("源代码的重要性+编译器底层理解的重要性！")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("（1）如何定义1个『只能』在『堆』上生成对象的类？")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("ul",[s("li",[this._v("在C++中，为了让某个类只能通过new来创建（即如果直接创建对象，编译器将报错），应该（）")]),this._v(" "),s("li",[this._v("将『析构函数』设为『私有』")]),this._v(" "),s("li",[this._v("原因：C++是静态")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("blockquote",[s("p",[this._v("（2）如何定义1个『只能』在『栈』上生成对象的类？")])])},function(){var t=this,s=t.$createElement,n=t._self._c||s;return n("ul",[n("li",[t._v("将new和delete重载为『私有』")]),t._v(" "),n("li",[t._v("原因：在堆上生成对象，使用new关键字操作。看过源代码知道过程是2步！！")]),t._v(" "),n("li",[t._v("1、使用operator new在『堆』上找可用的内存，分配给对象")]),t._v(" "),n("li",[t._v("2、调用构造函数生成对象")]),t._v(" "),n("li",[t._v("所以，如果将new操作设置为『私有』，那么第1阶段就不能完成。『就不能在堆上生成对象』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("h2",{attrs:{id:"✅杂谈"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#✅杂谈"}},[this._v("#")]),this._v(" ✅杂谈")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_01-常量表达式"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_01-常量表达式"}},[this._v("#")]),this._v(" 01.常量表达式")])},function(){var t=this.$createElement,s=this._self._c||t;return s("h3",{attrs:{id:"_02-c-98关键字"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#_02-c-98关键字"}},[this._v("#")]),this._v(" 02.C++98关键字")])},function(){var t=this.$createElement,s=this._self._c||t;return s("p",[this._v("1、"),s("code",[this._v("static")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("修改变量或函数存储的形式，比如"),s("code",[this._v(".data")]),this._v("，"),s("code",[this._v(".bss")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("作用是：穿透作用域、『C++ primer PXX好像是这么说的』")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("2、"),s("code",[this._v("const")])]),this._v(" "),s("ul",[s("li",[this._v("修改变量or函数的只读方式")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("3、"),s("code",[this._v("inline")])])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("建议在“编译期”，直接将整个函数的代码插入调用语句处")])])},function(){var t=this.$createElement,s=this._self._c||t;return s("li",[s("p",[this._v("4、"),s("code",[this._v("friend")])]),this._v(" "),s("ul",[s("li",[this._v("声明友元，包括，友元函数，友元类")])])])}],!1,null,null,null);s.default=e.exports}}]);