<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>清羽天的博客</title><link>https://songhongblog.top/</link><description>Good Luck To You!</description><item><title>解锁 C++ 面向对象核心：继承与多态的深度解析与实战</title><link>https://songhongblog.top/?id=36</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;继承（Inheritance）和多态（Polymorphism）是 C++ 面向对象编程（OOP）的三大核心特性（封装、继承、多态）中最能体现 “代码复用” 和 “动态行为” 的部分。继承让我们可以基于已有类创建新类，实现代码复用；多态则让不同类的对象能以统一的方式响应同一行为，提升代码的灵活性和扩展性。本文将从底层逻辑到实战场景，彻底讲清继承与多态的本质、用法和避坑技巧。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、继承：站在已有类的 “肩膀上” 编程&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 为什么需要继承？&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;假设我们要定义 “学生”“老师”“员工” 三个类，它们都包含 “姓名、年龄、性别” 等公共属性，以及 “打印基本信息” 的公共行为。如果重复编写这些代码，会导致冗余且难以维护：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4xoc7p4&quot; data-popupid=&quot;4xoc7p4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0uhp4zo&quot; data-popupid=&quot;0uhp4zo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;h9wq23r&quot; data-popupid=&quot;h9wq23r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qfbit19&quot; data-popupid=&quot;qfbit19&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ij7s30m&quot; data-popupid=&quot;ij7s30m&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;冗余的代码：每个类重复定义相同属性和方法class&amp;nbsp;Student&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&amp;nbsp;gender;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printBaseInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，性别：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;gender&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;学生特有属性/方法
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;studentId;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;study()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;学习&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Teacher&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&amp;nbsp;gender;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printBaseInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，性别：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;gender&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;老师特有属性/方法
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;teacherId;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;teach()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;授课&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;继承的核心价值是&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;提取公共代码，实现复用&lt;/span&gt;：我们可以定义一个 “基类（父类）”&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;Person&lt;/code&gt;，包含所有类的公共部分，再让&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;Student&lt;/code&gt;、&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;Teacher&lt;/code&gt;作为 “派生类（子类）” 继承&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;Person&lt;/code&gt;，仅需实现特有属性和方法：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jsbqh79&quot; data-popupid=&quot;jsbqh79&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5wib9c4&quot; data-popupid=&quot;5wib9c4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;90tuow4&quot; data-popupid=&quot;90tuow4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;m8d6x4s&quot; data-popupid=&quot;m8d6x4s&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1hjfuox&quot; data-popupid=&quot;1hjfuox&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;基类：公共属性和方法class&amp;nbsp;Person&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&amp;nbsp;gender;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printBaseInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，性别：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;gender&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};//&amp;nbsp;派生类：继承Person，仅实现特有部分class&amp;nbsp;Student&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Person&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;studentId;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;study()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;学习&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Teacher&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Person&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;teacherId;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;teach()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;授课&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这样既减少了代码冗余，又让结构更清晰 —— 这就是继承的核心：&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;复用基类的代码，扩展派生类的功能&lt;/span&gt;。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 继承的基本语法与核心概念&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;语法格式：&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vh3omvc&quot; data-popupid=&quot;vh3omvc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0sphm6r&quot; data-popupid=&quot;0sphm6r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xej6oxk&quot; data-popupid=&quot;xej6oxk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mqnkvwl&quot; data-popupid=&quot;mqnkvwl&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qh1s7q5&quot; data-popupid=&quot;qh1s7q5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;派生类名&amp;nbsp;:&amp;nbsp;继承方式&amp;nbsp;基类名&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;派生类的成员（特有属性/方法）};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;继承方式（权限控制）：&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;C++ 支持三种继承方式，核心影响派生类对基类成员的访问权限：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;继承方式&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;基类 public 成员&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;基类 protected 成员&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;基类 private 成员&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;public&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 public&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 protected&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;不可访问&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;protected&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 protected&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 protected&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;不可访问&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;private&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 private&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;派生类 private&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;不可访问&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;blockquote class=&quot;auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0px 0px 5.45455px; border-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(208, 215, 222); border-image: initial; margin: 12px 0px; padding: 0px 24px; font-size: 24px; font-weight: 600; line-height: 36px; --md-box-samantha-normal-text-color: rgba(0,0,0,.55); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 36px; font-weight: 400; overflow-anchor: auto;&quot;&gt;关键结论：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;ol class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;基类 private 成员无论哪种继承方式，派生类都无法直接访问（需通过基类 public/protected 接口）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;实际开发中优先用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 5.4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 21.6px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 5.4px; overflow-anchor: auto;&quot;&gt;public&lt;/code&gt;继承（保持基类接口的开放性，符合 “is-a” 关系）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 5.4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 21.6px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 5.4px; overflow-anchor: auto;&quot;&gt;protected&lt;/code&gt;继承用于 “继承但不对外暴露”，&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 5.4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 21.6px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 5.4px; overflow-anchor: auto;&quot;&gt;private&lt;/code&gt;继承几乎不用（等价于 “组合”）。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/blockquote&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：继承方式的权限验证&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;oks2geu&quot; data-popupid=&quot;oks2geu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;czer8bm&quot; data-popupid=&quot;czer8bm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ooyznlz&quot; data-popupid=&quot;ooyznlz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jn12sed&quot; data-popupid=&quot;jn12sed&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4xujnm2&quot; data-popupid=&quot;4xujnm2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;pub;protected:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;pro;private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;pri;};//&amp;nbsp;public继承class&amp;nbsp;DerivedPub&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;test()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pub&amp;nbsp;=&amp;nbsp;1;&amp;nbsp;&amp;nbsp;//&amp;nbsp;合法：public→public
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pro&amp;nbsp;=&amp;nbsp;2;&amp;nbsp;&amp;nbsp;//&amp;nbsp;合法：protected→protected
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;pri&amp;nbsp;=&amp;nbsp;3;&amp;nbsp;//&amp;nbsp;非法：private成员不可访问
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DerivedPub&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.pub&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;&amp;nbsp;//&amp;nbsp;合法：public成员类外可访问
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;d.pro&amp;nbsp;=&amp;nbsp;20;&amp;nbsp;//&amp;nbsp;非法：protected成员类外不可访问
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 派生类的构造与析构：先基后派，先派后基&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;派生类对象的生命周期遵循固定顺序：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;构造&lt;/span&gt;：先调用基类构造函数 → 再调用派生类构造函数；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;析构&lt;/span&gt;：先调用派生类析构函数 → 再调用基类析构函数。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例验证：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8mzm5z6&quot; data-popupid=&quot;8mzm5z6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qz67w70&quot; data-popupid=&quot;qz67w70&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;eahy011&quot; data-popupid=&quot;eahy011&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dvtppag&quot; data-popupid=&quot;dvtppag&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;q7od9gm&quot; data-popupid=&quot;q7od9gm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Base()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base构造函数&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;~Base()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base析构函数&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Derived&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived构造函数&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;~Derived()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived析构函数&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出顺序：
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived析构函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base析构函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;带参构造的传递：&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;若基类有带参构造函数，派生类需显式调用（编译器不再生成默认构造）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jl4t4tz&quot; data-popupid=&quot;jl4t4tz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;empqm9u&quot; data-popupid=&quot;empqm9u&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;reff3pa&quot; data-popupid=&quot;reff3pa&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;x4vno8j&quot; data-popupid=&quot;x4vno8j&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vf7vqrh&quot; data-popupid=&quot;vf7vqrh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;num;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Base(int&amp;nbsp;n)&amp;nbsp;:&amp;nbsp;num(n)&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base带参构造：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;num&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Derived&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;派生类构造函数：初始化列表中调用基类带参构造
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived(int&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;m)&amp;nbsp;:&amp;nbsp;Base(n),&amp;nbsp;num2(m)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived带参构造：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;num2&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;num2;};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived&amp;nbsp;d(10,&amp;nbsp;20);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出：
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base带参构造：10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived带参构造：20
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 继承的常见场景：重写与隐藏&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;（1）重写（Override）：派生类覆盖基类的虚函数（多态基础）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;需满足三个条件：函数名、参数列表、返回值完全相同，且基类函数加&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;virtual&lt;/code&gt;。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;（2）隐藏（Hide）：派生类同名函数隐藏基类所有同名函数&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;即使参数不同，派生类的同名函数也会 “隐藏” 基类函数（而非重载）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;35s7azj&quot; data-popupid=&quot;35s7azj&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vpqsglq&quot; data-popupid=&quot;vpqsglq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8ql42gx&quot; data-popupid=&quot;8ql42gx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kai50u2&quot; data-popupid=&quot;kai50u2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kiula8b&quot; data-popupid=&quot;kiula8b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;func(int&amp;nbsp;a)&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base::func(int)：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Derived&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏基类的func(int)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;func()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived::func()&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.func();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;合法：调用派生类func()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;d.func(10);&amp;nbsp;//&amp;nbsp;非法：基类func(int)被隐藏
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.Base::func(10);&amp;nbsp;//&amp;nbsp;合法：显式调用基类函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、多态：同一接口，不同行为&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 多态的本质：动态绑定（运行时决策）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;多态的核心是 “&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;一个接口，多种实现&lt;/span&gt;”—— 基类指针 / 引用指向派生类对象时，调用的函数由对象的实际类型决定（而非指针 / 引用的类型）。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;对比：静态绑定 vs 动态绑定&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;绑定方式&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;决策时机&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;依据&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;示例&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;静态绑定（早绑定）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;编译期&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;指针 / 引用的类型&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;普通函数、隐藏的函数&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;动态绑定（晚绑定）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;运行期&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;对象的实际类型&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;虚函数的重写&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：无多态（静态绑定）vs 有多态（动态绑定）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3ruzzwh&quot; data-popupid=&quot;3ruzzwh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f0vgfs5&quot; data-popupid=&quot;f0vgfs5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4ozgc2e&quot; data-popupid=&quot;4ozgc2e&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mxp1hcw&quot; data-popupid=&quot;mxp1hcw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5cfvkl2&quot; data-popupid=&quot;5cfvkl2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;无多态：静态绑定class&amp;nbsp;Animal&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;动物叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;普通函数};class&amp;nbsp;Cat&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Animal&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;猫叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;隐藏基类函数};//&amp;nbsp;有多态：动态绑定（基类函数加virtual）class&amp;nbsp;AnimalPoly&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;动物叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;虚函数};class&amp;nbsp;CatPoly&amp;nbsp;:&amp;nbsp;public&amp;nbsp;AnimalPoly&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;override&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;猫叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;重写（override可选，建议加）};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;无多态：指针类型是Animal，调用Animal::speak()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Animal*&amp;nbsp;p1&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Cat;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p1-&amp;gt;speak();&amp;nbsp;//&amp;nbsp;输出：动物叫

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;有多态：对象实际类型是CatPoly，调用CatPoly::speak()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AnimalPoly*&amp;nbsp;p2&amp;nbsp;=&amp;nbsp;new&amp;nbsp;CatPoly;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p2-&amp;gt;speak();&amp;nbsp;//&amp;nbsp;输出：猫叫

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 多态的实现条件（缺一不可）：&lt;/h3&gt;&lt;ol class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;基类中声明&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;虚函数&lt;/span&gt;（加&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;virtual&lt;/code&gt;关键字）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;派生类&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;重写&lt;/span&gt;基类的虚函数（函数名、参数、返回值完全一致）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;通过&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;基类指针 / 引用&lt;/span&gt;调用虚函数。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;blockquote class=&quot;auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0px 0px 5.45455px; border-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(208, 215, 222); border-image: initial; margin: 12px 0px; padding: 0px 24px; font-size: 24px; font-weight: 600; line-height: 36px; --md-box-samantha-normal-text-color: rgba(0,0,0,.55); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 36px; font-weight: 400; overflow-anchor: auto;&quot;&gt;补充：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.55); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 16px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.55) !important;&quot;&gt;override&lt;/code&gt;关键字（C++11）：显式声明重写，编译器会校验是否符合重写规则（避免拼写错误），建议必加。&lt;/div&gt;&lt;/blockquote&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 虚函数的底层：虚函数表（vtable）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;C++ 通过 “虚函数表” 实现多态：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;每个包含虚函数的类，编译器会生成一个&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;虚函数表（vtable）&lt;/span&gt;&amp;nbsp;—— 存储类中所有虚函数的地址；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;每个对象会包含一个&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;虚表指针（vptr）&lt;/span&gt;&amp;nbsp;—— 指向所属类的虚函数表；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;运行时，通过 vptr 找到 vtable，再调用对应虚函数（动态绑定的核心）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;内存布局示例：&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bb06aez&quot; data-popupid=&quot;bb06aez&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nguztnn&quot; data-popupid=&quot;nguztnn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;m7xw81x&quot; data-popupid=&quot;m7xw81x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f7klqzw&quot; data-popupid=&quot;f7klqzw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;rcxtf8g&quot; data-popupid=&quot;rcxtf8g&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;void&amp;nbsp;func1()&amp;nbsp;{}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;void&amp;nbsp;func2()&amp;nbsp;{}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;num;};class&amp;nbsp;Derived&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;func1()&amp;nbsp;override&amp;nbsp;{}&amp;nbsp;//&amp;nbsp;重写func1，vtable中替换为Derived::func1地址};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Base&lt;/code&gt;对象内存：vptr（8 字节） + num（4 字节） = 12 字节（内存对齐）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Derived&lt;/code&gt;对象内存：vptr（指向 Derived 的 vtable） + num（4 字节）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Derived 的 vtable：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Derived::func1()&lt;/code&gt;&amp;nbsp;地址 +&amp;nbsp;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Base::func2()&lt;/code&gt;&amp;nbsp;地址。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 纯虚函数与抽象类：强制派生类实现&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;纯虚函数是 “没有实现的虚函数”，格式为：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;virtual 返回值 函数名(参数) = 0;&lt;/code&gt;。&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;包含纯虚函数的类称为&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;抽象类&lt;/span&gt;，核心特征：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;无法实例化对象（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Animal a;&lt;/code&gt;&amp;nbsp;编译报错）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;派生类必须重写所有纯虚函数，否则派生类也是抽象类；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;核心用途：定义接口规范（比如 “所有动物都必须实现 speak ()”）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：抽象类与纯虚函数&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vt2tlh4&quot; data-popupid=&quot;vt2tlh4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ixm7krp&quot; data-popupid=&quot;ixm7krp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3a2f25n&quot; data-popupid=&quot;3a2f25n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pkt0fhq&quot; data-popupid=&quot;pkt0fhq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;55g6mzc&quot; data-popupid=&quot;55g6mzc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;抽象类：包含纯虚函数class&amp;nbsp;Animal&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;纯虚函数：仅定义接口，无实现
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;void&amp;nbsp;move()&amp;nbsp;=&amp;nbsp;0;};//&amp;nbsp;派生类：必须实现所有纯虚函数class&amp;nbsp;Dog&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Animal&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;override&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;狗叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;move()&amp;nbsp;override&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;狗跑&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Bird&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Animal&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;speak()&amp;nbsp;override&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;鸟叫&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;move()&amp;nbsp;override&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;鸟飞&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};//&amp;nbsp;多态函数：接收抽象类引用，适配所有派生类void&amp;nbsp;animalDo(Animal&amp;amp;&amp;nbsp;a)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a.speak();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a.move();}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dog&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Bird&amp;nbsp;b;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;animalDo(d);&amp;nbsp;//&amp;nbsp;输出：狗叫&amp;nbsp;→&amp;nbsp;狗跑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;animalDo(b);&amp;nbsp;//&amp;nbsp;输出：鸟叫&amp;nbsp;→&amp;nbsp;鸟飞
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;5. 析构函数与多态：虚析构函数&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;若基类指针指向派生类对象，删除指针时默认只调用基类析构函数（派生类析构不执行，导致内存泄漏）。解决方案：将基类析构函数设为虚函数（&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;虚析构&lt;/span&gt;）。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;错误示例：非虚析构导致内存泄漏&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;t1c35e8&quot; data-popupid=&quot;t1c35e8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;55ndcmf&quot; data-popupid=&quot;55ndcmf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pamhdg5&quot; data-popupid=&quot;pamhdg5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ag0osdw&quot; data-popupid=&quot;ag0osdw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1wq4cer&quot; data-popupid=&quot;1wq4cer&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Base()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base构造&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;~Base()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base析构&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;非虚析构};class&amp;nbsp;Derived&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int*&amp;nbsp;arr&amp;nbsp;=&amp;nbsp;new&amp;nbsp;int[10];&amp;nbsp;//&amp;nbsp;堆内存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Derived()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived构造&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;~Derived()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete[]&amp;nbsp;arr;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Derived析构&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Base*&amp;nbsp;p&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Derived;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p;&amp;nbsp;//&amp;nbsp;仅调用Base析构，Derived析构未执行&amp;nbsp;→&amp;nbsp;arr内存泄漏
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出：
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base构造
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived构造
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base析构
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;正确示例：虚析构函数&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kibehws&quot; data-popupid=&quot;kibehws&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9l1bzfp&quot; data-popupid=&quot;9l1bzfp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dmy8ma7&quot; data-popupid=&quot;dmy8ma7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;154oq1w&quot; data-popupid=&quot;154oq1w&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ct24v89&quot; data-popupid=&quot;ct24v89&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Base&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;virtual&amp;nbsp;~Base()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Base析构&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;虚析构};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Base*&amp;nbsp;p&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Derived;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p;&amp;nbsp;//&amp;nbsp;先调用Derived析构，再调用Base析构
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出：
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base构造
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived构造
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Derived析构
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;Base析构
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;blockquote class=&quot;auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0px 0px 5.45455px; border-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(208, 215, 222); border-image: initial; margin: 12px 0px; padding: 0px 24px; font-size: 24px; font-weight: 600; line-height: 36px; --md-box-samantha-normal-text-color: rgba(0,0,0,.55); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 36px; font-weight: 400; overflow-anchor: auto;&quot;&gt;结论：只要类作为基类被继承，且包含堆内存，就必须将析构函数设为虚函数。&lt;/div&gt;&lt;/blockquote&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、继承与多态的避坑指南&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 多继承的菱形问题（钻石继承）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;多个派生类继承同一个基类，又被同一个类继承，导致基类成员多次继承，产生二义性：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qjn94fn&quot; data-popupid=&quot;qjn94fn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qk840kj&quot; data-popupid=&quot;qk840kj&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1bcedsy&quot; data-popupid=&quot;1bcedsy&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6nqpqts&quot; data-popupid=&quot;6nqpqts&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;88y69jz&quot; data-popupid=&quot;88y69jz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;菱形继承结构class&amp;nbsp;A&amp;nbsp;{&amp;nbsp;public:&amp;nbsp;int&amp;nbsp;num;&amp;nbsp;};class&amp;nbsp;B&amp;nbsp;:&amp;nbsp;public&amp;nbsp;A&amp;nbsp;{};class&amp;nbsp;C&amp;nbsp;:&amp;nbsp;public&amp;nbsp;A&amp;nbsp;{};class&amp;nbsp;D&amp;nbsp;:&amp;nbsp;public&amp;nbsp;B,&amp;nbsp;public&amp;nbsp;C&amp;nbsp;{};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;d.num&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;非法：二义性（B::num&amp;nbsp;或&amp;nbsp;C::num）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.B::num&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;合法：显式指定
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.C::num&amp;nbsp;=&amp;nbsp;20;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;解决方案&lt;/span&gt;：虚继承（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;virtual&lt;/code&gt;），让共同基类只被继承一次：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7hnuyt3&quot; data-popupid=&quot;7hnuyt3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2aj2h90&quot; data-popupid=&quot;2aj2h90&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zlh3lts&quot; data-popupid=&quot;zlh3lts&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mm4fc7o&quot; data-popupid=&quot;mm4fc7o&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wvu1n7t&quot; data-popupid=&quot;wvu1n7t&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;B&amp;nbsp;:&amp;nbsp;virtual&amp;nbsp;public&amp;nbsp;A&amp;nbsp;{};class&amp;nbsp;C&amp;nbsp;:&amp;nbsp;virtual&amp;nbsp;public&amp;nbsp;A&amp;nbsp;{};class&amp;nbsp;D&amp;nbsp;:&amp;nbsp;public&amp;nbsp;B,&amp;nbsp;public&amp;nbsp;C&amp;nbsp;{};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;D&amp;nbsp;d;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d.num&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;合法：虚继承消除二义性
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 虚函数的常见错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;重写时参数不一致：比如基类&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;virtual void func(int)&lt;/code&gt;，派生类&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;void func(double)&lt;/code&gt;&amp;nbsp;→ 不是重写，是隐藏；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;基类函数未加&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;virtual&lt;/code&gt;：即使派生类重写，也无法触发多态（静态绑定）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;用对象调用虚函数：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Animal a = Cat(); a.speak();&lt;/code&gt;&amp;nbsp;→ 对象切片，仅调用基类函数（需用指针 / 引用）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 抽象类的误用&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;试图实例化抽象类：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Animal a;&lt;/code&gt;&amp;nbsp;→ 编译报错；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;派生类未实现所有纯虚函数：派生类仍为抽象类，无法实例化。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 继承的 “is-a” 原则&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;public 继承需符合 “is-a” 关系（比如 “学生是一个人”），若不符合，应使用 “组合” 而非继承：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ug06gfw&quot; data-popupid=&quot;ug06gfw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fbbx4o4&quot; data-popupid=&quot;fbbx4o4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;catoqe8&quot; data-popupid=&quot;catoqe8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;a5p47eh&quot; data-popupid=&quot;a5p47eh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zhktl7v&quot; data-popupid=&quot;zhktl7v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;错误：Car继承Engine（汽车不是引擎，而是包含引擎）class&amp;nbsp;Engine&amp;nbsp;{&amp;nbsp;public:&amp;nbsp;void&amp;nbsp;run()&amp;nbsp;{}&amp;nbsp;};class&amp;nbsp;Car&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Engine&amp;nbsp;{};//&amp;nbsp;正确：组合（Car包含Engine对象）class&amp;nbsp;Car&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Engine&amp;nbsp;e;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;run()&amp;nbsp;{&amp;nbsp;e.run();&amp;nbsp;}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、总结：继承与多态的核心取舍&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;特性&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;核心价值&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;适用场景&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;继承&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;代码复用，扩展基类功能&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;类之间存在 “is-a” 关系（学生→人）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;多态&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;动态绑定，统一接口适配不同实现&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;需根据对象类型动态执行不同逻辑（动物叫）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;抽象类&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;定义接口规范，强制派生类实现&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;框架设计（定义标准，不关心具体实现）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;虚析构&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;确保派生类析构函数被调用&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;基类包含堆内存，需通过基类指针释放&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;继承与多态是 C++ 面向对象的 “灵魂”：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;继承解决 “代码复用” 问题，让我们无需重复编写公共逻辑；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;多态解决 “接口统一” 问题，让代码更灵活、易扩展（比如新增&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Fish&lt;/code&gt;类，只需继承&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Animal&lt;/code&gt;并实现&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;speak()&lt;/code&gt;，无需修改&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;animalDo()&lt;/code&gt;函数）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 05 Dec 2025 14:38:46 +0800</pubDate></item><item><title>从面向过程到面向对象：吃透 C++ 类与对象的核心逻辑</title><link>https://songhongblog.top/?id=35</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在 C++ 编程体系中，类（Class）和对象（Object）是面向对象编程（OOP）的基石。相比于 C 语言的 “面向过程”（以函数为核心），C++ 的 “面向对象” 通过封装、继承、多态三大特性，让代码更贴合现实世界的逻辑，也更易维护和扩展。本文将从 “类是什么、对象怎么用” 出发，拆解类的定义、对象的创建、成员访问、构造 / 析构函数等核心知识点，帮你彻底理解类与对象的本质。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、先搞懂：为什么需要类和对象？&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;面向过程编程的痛点：比如要描述 “学生” 这个实体，用 C 语言需要定义独立的变量和函数，数据和行为分离，代码冗余且易出错：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--c hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ci2fxen&quot; data-popupid=&quot;ci2fxen&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;c&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;s1kg3it&quot; data-popupid=&quot;s1kg3it&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;53wjt56&quot; data-popupid=&quot;53wjt56&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ll9bcm5&quot; data-popupid=&quot;ll9bcm5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xxwgu76&quot; data-popupid=&quot;xxwgu76&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-c&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;C语言：数据与行为分离struct&amp;nbsp;Student&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&amp;nbsp;name[20];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;score;};//&amp;nbsp;独立的函数操作结构体void&amp;nbsp;setStudent(struct&amp;nbsp;Student*&amp;nbsp;s,&amp;nbsp;const&amp;nbsp;char*&amp;nbsp;name,&amp;nbsp;int&amp;nbsp;age,&amp;nbsp;float&amp;nbsp;score)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;strcpy(s-&amp;gt;name,&amp;nbsp;name);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s-&amp;gt;age&amp;nbsp;=&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s-&amp;gt;score&amp;nbsp;=&amp;nbsp;score;}void&amp;nbsp;printStudent(struct&amp;nbsp;Student*&amp;nbsp;s)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printf(&amp;quot;姓名：%s，年龄：%d，成绩：%.1f\n&amp;quot;,&amp;nbsp;s-&amp;gt;name,&amp;nbsp;s-&amp;gt;age,&amp;nbsp;s-&amp;gt;score);}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;而 C++ 的类可以将 “学生的数据（属性）” 和 “操作数据的行为（方法）” 封装在一起，形成一个完整的 “实体”：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;w9v3wrf&quot; data-popupid=&quot;w9v3wrf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mtsucms&quot; data-popupid=&quot;mtsucms&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;upbo00z&quot; data-popupid=&quot;upbo00z&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;t73rrwz&quot; data-popupid=&quot;t73rrwz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xrq9yn6&quot; data-popupid=&quot;xrq9yn6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;C++类：数据与行为封装class&amp;nbsp;Student&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;属性（成员变量）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;score;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;方法（成员函数）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;setInfo(string&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;a,&amp;nbsp;float&amp;nbsp;s)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;a;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;score&amp;nbsp;=&amp;nbsp;s;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，成绩：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;score&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;核心优势&lt;/span&gt;：数据和行为绑定，代码更内聚、更符合 “学生” 这个实体的自然逻辑。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、类的本质：自定义数据类型的 “蓝图”&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 类的定义：从语法到核心&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;类是 C++ 自定义的 “复合数据类型”，它定义了某一类实体的&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;属性（成员变量）&lt;/span&gt;&amp;nbsp;和&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;行为（成员函数）&lt;/span&gt;，相当于创建对象的 “蓝图” 或 “模板”。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;基本语法结构：&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8y3lw0b&quot; data-popupid=&quot;8y3lw0b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hz0htu9&quot; data-popupid=&quot;hz0htu9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;757wnx0&quot; data-popupid=&quot;757wnx0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fwcm1j7&quot; data-popupid=&quot;fwcm1j7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;yqs609k&quot; data-popupid=&quot;yqs609k&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;类名&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;访问权限修饰符：public&amp;nbsp;/&amp;nbsp;private&amp;nbsp;/&amp;nbsp;protected（默认private）public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;成员变量（属性）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;数据类型&amp;nbsp;变量名;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;成员函数（行为）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;返回值类型&amp;nbsp;函数名(参数列表)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;函数体
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;私有成员（仅类内部可访问）};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;关键概念：访问权限修饰符&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;修饰符&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;访问范围&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;核心用途&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;public&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;类内、类外、子类均可访问&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;对外提供的接口（如成员函数）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;private&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;仅类内部可访问（默认）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;封装内部数据，避免外部直接修改&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;protected&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;类内、子类可访问，类外不可访问&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;继承场景下的权限控制&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;blockquote class=&quot;auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0px 0px 5.45455px; border-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(208, 215, 222); border-image: initial; margin: 12px 0px; padding: 0px 24px; font-size: 24px; font-weight: 600; line-height: 36px; --md-box-samantha-normal-text-color: rgba(0,0,0,.55); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 36px; font-weight: 400; overflow-anchor: auto;&quot;&gt;封装的核心：将数据（成员变量）设为 private，通过 public 的成员函数（get/set）访问，避免外部直接修改数据导致的错误。&lt;/div&gt;&lt;/blockquote&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 类的定义示例：规范的封装写法&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;g7kb75b&quot; data-popupid=&quot;g7kb75b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jggyi2f&quot; data-popupid=&quot;jggyi2f&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wtyirao&quot; data-popupid=&quot;wtyirao&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;enuxdap&quot; data-popupid=&quot;enuxdap&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;oszabsb&quot; data-popupid=&quot;oszabsb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#include&amp;nbsp;&amp;lt;iostream&amp;gt;#include&amp;nbsp;&amp;lt;string&amp;gt;using&amp;nbsp;namespace&amp;nbsp;std;//&amp;nbsp;定义Student类（规范封装：成员变量私有，通过接口访问）class&amp;nbsp;Student&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;私有成员变量：外部无法直接访问
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;score;public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;公有成员函数：对外提供的接口
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置学生信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;setInfo(string&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;a,&amp;nbsp;float&amp;nbsp;s)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;可以在内部做数据校验
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(a&amp;nbsp;&amp;lt;&amp;nbsp;0&amp;nbsp;||&amp;nbsp;a&amp;nbsp;&amp;gt;&amp;nbsp;120)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;年龄非法！&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;else&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;a;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;score&amp;nbsp;=&amp;nbsp;s;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取姓名（只读）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;getName()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取成绩（只读）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;getScore()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;score;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;打印信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，成绩：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;score&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、对象的本质：类的 “实例化”&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;类是 “蓝图”，对象是根据蓝图创建的 “具体实例”—— 一个类可以创建多个对象，每个对象拥有独立的成员变量（属性），但共享类的成员函数（行为）。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 对象的创建与使用&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;方式 1：栈上创建对象（常用）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;24z6zuz&quot; data-popupid=&quot;24z6zuz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;041j7pn&quot; data-popupid=&quot;041j7pn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;efozwkg&quot; data-popupid=&quot;efozwkg&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kj5rzve&quot; data-popupid=&quot;kj5rzve&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xmc9394&quot; data-popupid=&quot;xmc9394&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;栈上创建Student对象：stu1、stu2是两个独立的实例
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Student&amp;nbsp;stu1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Student&amp;nbsp;stu2;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用成员函数：对象名.成员函数()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu1.setInfo(&amp;quot;张三&amp;quot;,&amp;nbsp;18,&amp;nbsp;90.5);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu2.setInfo(&amp;quot;李四&amp;quot;,&amp;nbsp;19,&amp;nbsp;85.0);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用打印函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu1.printInfo();&amp;nbsp;//&amp;nbsp;输出：姓名：张三，年龄：18，成绩：90.5
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu2.printInfo();&amp;nbsp;//&amp;nbsp;输出：姓名：李四，年龄：19，成绩：85.0

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;访问公有接口（获取私有成员）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;stu1.getName()&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：张三
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;stu1.age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;错误：private成员，类外无法访问
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方式 2：堆上创建对象（用 new/delete）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f5qiv81&quot; data-popupid=&quot;f5qiv81&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5xxvtoy&quot; data-popupid=&quot;5xxvtoy&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;95wic5w&quot; data-popupid=&quot;95wic5w&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;15ybapo&quot; data-popupid=&quot;15ybapo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1atgadu&quot; data-popupid=&quot;1atgadu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;堆上创建对象：返回指向对象的指针
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Student*&amp;nbsp;pStu&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Student;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用成员函数：指针-&amp;gt;成员函数()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStu-&amp;gt;setInfo(&amp;quot;王五&amp;quot;,&amp;nbsp;20,&amp;nbsp;88.5);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStu-&amp;gt;printInfo();&amp;nbsp;//&amp;nbsp;输出：姓名：王五，年龄：20，成绩：88.5

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;释放堆内存（必须手动delete，否则内存泄漏）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;pStu;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pStu&amp;nbsp;=&amp;nbsp;nullptr;&amp;nbsp;//&amp;nbsp;避免野指针
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 类与对象的内存布局&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;每个对象的内存仅存储&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;成员变量&lt;/span&gt;（成员函数存储在代码区，所有对象共享）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;空类（无成员变量）的大小为 1 字节（编译器为了区分不同对象的地址）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例验证：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;10xvimh&quot; data-popupid=&quot;10xvimh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f0mpwi4&quot; data-popupid=&quot;f0mpwi4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1vrdspv&quot; data-popupid=&quot;1vrdspv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;86difo2&quot; data-popupid=&quot;86difo2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ig1g04x&quot; data-popupid=&quot;ig1g04x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;EmptyClass&amp;nbsp;{};&amp;nbsp;//&amp;nbsp;空类cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;sizeof(EmptyClass)&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：1class&amp;nbsp;Test&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a;&amp;nbsp;//&amp;nbsp;4字节
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;double&amp;nbsp;b;&amp;nbsp;//&amp;nbsp;8字节
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;func()&amp;nbsp;{}&amp;nbsp;//&amp;nbsp;成员函数不占对象内存};Test&amp;nbsp;t;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;sizeof(t)&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：12（内存对齐后，4+8=12）&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、类的核心函数：构造函数与析构函数&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;对象的生命周期：创建（初始化）→ 使用 → 销毁（清理）。构造函数负责初始化，析构函数负责清理，二者均由编译器自动调用，无需手动触发。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 构造函数：对象的 “初始化器”&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;核心特征：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;函数名与类名完全相同，无返回值（连 void 都没有）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;对象创建时自动调用（栈 / 堆创建均会调用）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;支持重载（参数不同）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;若未显式定义，编译器会生成 “默认构造函数”（无参、空实现）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分类与示例：&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6j3v6mk&quot; data-popupid=&quot;6j3v6mk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;h7pwubg&quot; data-popupid=&quot;h7pwubg&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8r7b57i&quot; data-popupid=&quot;8r7b57i&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0w66blh&quot; data-popupid=&quot;0w66blh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7386qru&quot; data-popupid=&quot;7386qru&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Person&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;默认构造函数（无参）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;&amp;quot;未知&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;默认构造函数调用&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;带参构造函数（重载）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person(string&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;a)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;a;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;带参构造函数调用&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;3.&amp;nbsp;拷贝构造函数（用已有对象初始化新对象）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person(const&amp;nbsp;Person&amp;amp;&amp;nbsp;p)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;p.name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;p.age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;拷贝构造函数调用&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;print()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用默认构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person&amp;nbsp;p1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p1.print();&amp;nbsp;//&amp;nbsp;输出：姓名：未知，年龄：0

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用带参构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person&amp;nbsp;p2(&amp;quot;赵六&amp;quot;,&amp;nbsp;22);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p2.print();&amp;nbsp;//&amp;nbsp;输出：姓名：赵六，年龄：22

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用拷贝构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Person&amp;nbsp;p3&amp;nbsp;=&amp;nbsp;p2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p3.print();&amp;nbsp;//&amp;nbsp;输出：姓名：赵六，年龄：22

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 析构函数：对象的 “清理员”&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;核心特征：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;函数名是&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;~类名&lt;/code&gt;，无返回值、无参数；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;对象销毁时自动调用（栈对象出作用域、堆对象 delete 时）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;仅能有一个析构函数（不能重载）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;若未显式定义，编译器生成 “默认析构函数”（空实现）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;核心用途：释放对象占用的资源（如堆内存、文件句柄）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：析构函数释放堆内存&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vcbgvql&quot; data-popupid=&quot;vcbgvql&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;tcgqqy2&quot; data-popupid=&quot;tcgqqy2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kxsiio9&quot; data-popupid=&quot;kxsiio9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fds91p2&quot; data-popupid=&quot;fds91p2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wfvve2r&quot; data-popupid=&quot;wfvve2r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;MyArray&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int*&amp;nbsp;arr;&amp;nbsp;//&amp;nbsp;堆数组指针
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;size;public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;构造函数：分配堆内存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyArray(int&amp;nbsp;s)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;size&amp;nbsp;=&amp;nbsp;s;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arr&amp;nbsp;=&amp;nbsp;new&amp;nbsp;int[size];&amp;nbsp;//&amp;nbsp;动态分配数组
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;构造函数：分配&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;size&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;个int内存&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;析构函数：释放堆内存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;~MyArray()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete[]&amp;nbsp;arr;&amp;nbsp;//&amp;nbsp;释放数组
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arr&amp;nbsp;=&amp;nbsp;nullptr;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;析构函数：释放堆内存&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyArray&amp;nbsp;arr(5);&amp;nbsp;//&amp;nbsp;栈对象：出{}时调用析构函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;//&amp;nbsp;此处输出：析构函数：释放堆内存

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyArray*&amp;nbsp;pArr&amp;nbsp;=&amp;nbsp;new&amp;nbsp;MyArray(10);&amp;nbsp;//&amp;nbsp;堆对象
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;pArr;&amp;nbsp;//&amp;nbsp;手动delete，调用析构函数&amp;nbsp;→&amp;nbsp;输出：析构函数：释放堆内存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、实战进阶：类的成员函数补充&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 成员函数的分文件编写（工程化规范）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;实际开发中，类的定义和实现需分离（头文件.h + 源文件.cpp），避免重复编译：&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;步骤 1：头文件（Student.h）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7nfwy9r&quot; data-popupid=&quot;7nfwy9r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;z6el9kd&quot; data-popupid=&quot;z6el9kd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qehcdzt&quot; data-popupid=&quot;qehcdzt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8bwaoto&quot; data-popupid=&quot;8bwaoto&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uni9tef&quot; data-popupid=&quot;uni9tef&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#pragma&amp;nbsp;once&amp;nbsp;//&amp;nbsp;防止头文件重复包含#include&amp;nbsp;&amp;lt;string&amp;gt;using&amp;nbsp;namespace&amp;nbsp;std;class&amp;nbsp;Student&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;name;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;age;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;score;public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;仅声明成员函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;setInfo(string&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;a,&amp;nbsp;float&amp;nbsp;s);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;getName();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;printInfo();};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;步骤 2：源文件（Student.cpp）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ytmwmil&quot; data-popupid=&quot;ytmwmil&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dtxe4w6&quot; data-popupid=&quot;dtxe4w6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r1gwqzr&quot; data-popupid=&quot;r1gwqzr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;w2cnnlo&quot; data-popupid=&quot;w2cnnlo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hxo52k3&quot; data-popupid=&quot;hxo52k3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#include&amp;nbsp;&amp;quot;Student.h&amp;quot;#include&amp;nbsp;&amp;lt;iostream&amp;gt;//&amp;nbsp;实现成员函数：类名::函数名void&amp;nbsp;Student::setInfo(string&amp;nbsp;n,&amp;nbsp;int&amp;nbsp;a,&amp;nbsp;float&amp;nbsp;s)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;age&amp;nbsp;=&amp;nbsp;a;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;score&amp;nbsp;=&amp;nbsp;s;}string&amp;nbsp;Student::getName()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;name;}void&amp;nbsp;Student::printInfo()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;姓名：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;name&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，年龄：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;age&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;，成绩：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;score&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;步骤 3：主函数（main.cpp）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;cub25lk&quot; data-popupid=&quot;cub25lk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1h8jfws&quot; data-popupid=&quot;1h8jfws&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;w7fmdbq&quot; data-popupid=&quot;w7fmdbq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;i652mzw&quot; data-popupid=&quot;i652mzw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mph509v&quot; data-popupid=&quot;mph509v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#include&amp;nbsp;&amp;quot;Student.h&amp;quot;int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Student&amp;nbsp;stu;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu.setInfo(&amp;quot;孙七&amp;quot;,&amp;nbsp;21,&amp;nbsp;92.0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stu.printInfo();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 静态成员：属于类，而非对象&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;静态成员（static）分为静态成员变量和静态成员函数，核心特征是 “归属于类，所有对象共享”。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：统计类的实例个数&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mbgwk27&quot; data-popupid=&quot;mbgwk27&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8fmnzxt&quot; data-popupid=&quot;8fmnzxt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kimurnm&quot; data-popupid=&quot;kimurnm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ahejiv5&quot; data-popupid=&quot;ahejiv5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;c7mdbhi&quot; data-popupid=&quot;c7mdbhi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Counter&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static&amp;nbsp;int&amp;nbsp;count;&amp;nbsp;//&amp;nbsp;静态成员变量：统计对象个数public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;构造函数：创建对象时count+1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Counter()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;count++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;静态成员函数：访问静态成员变量（无this指针）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static&amp;nbsp;int&amp;nbsp;getCount()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;this-&amp;gt;count&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;错误：静态函数无this指针
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;count;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};//&amp;nbsp;静态成员变量必须在类外初始化int&amp;nbsp;Counter::count&amp;nbsp;=&amp;nbsp;0;int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Counter&amp;nbsp;c1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Counter&amp;nbsp;c2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Counter&amp;nbsp;c3;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;静态成员函数：类名::函数名（无需创建对象）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;对象个数：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;Counter::getCount()&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、避坑指南：类与对象的常见错误&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 访问权限错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;直接访问 private 成员：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;stu.age = 18;&lt;/code&gt;&amp;nbsp;→ 编译报错，需通过 public 接口修改；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;类外调用 protected 成员：仅继承场景下子类可访问，类外禁止。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 构造函数使用错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;调用默认构造函数时加括号：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Person p1();&lt;/code&gt;&amp;nbsp;→ 这是函数声明，而非对象创建（正确：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Person p1;&lt;/code&gt;）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;浅拷贝问题：类中有堆内存成员时，默认拷贝构造函数会导致 “重复释放内存”，需自定义拷贝构造函数（深拷贝）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 析构函数遗漏&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;堆对象未 delete：导致内存泄漏；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;类中有堆内存成员时，未定义析构函数释放资源。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 静态成员初始化错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;静态成员变量未在类外初始化：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int Counter::count = 0;&lt;/code&gt;&amp;nbsp;不可省略。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;七、总结：类与对象的核心逻辑&lt;/h2&gt;&lt;ol class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;类&lt;/span&gt;：自定义数据类型，封装了属性（成员变量）和行为（成员函数），是创建对象的 “蓝图”；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;对象&lt;/span&gt;：类的实例，拥有独立的成员变量，共享成员函数，有明确的生命周期；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;构造函数&lt;/span&gt;：对象创建时初始化，支持重载，核心处理 “资源分配”；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;析构函数&lt;/span&gt;：对象销毁时清理，核心处理 “资源释放”；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;封装&lt;/span&gt;：通过访问权限控制，将数据隐藏，仅暴露必要接口，提升代码安全性。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;br/&gt;&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 05 Dec 2025 14:38:20 +0800</pubDate></item><item><title>深度解析 C++ 引用与指针：从本质到实战，理清核心差异</title><link>https://songhongblog.top/?id=34</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在 C++ 编程中，引用（Reference）和指针（Pointer）是两个高频且极易混淆的核心概念。二者都能间接操作内存中的数据，却有着截然不同的设计初衷、语法规则和使用场景。本文将从底层本质出发，拆解引用与指针的核心区别，结合实战案例讲清适用场景，帮你彻底摆脱 “什么时候用引用？什么时候用指针？” 的困惑。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、先搞懂：引用与指针的本质是什么？&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 指针：“指向内存地址的变量”&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;指针是一个&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;独立的变量&lt;/span&gt;，它存储的是另一个变量的内存地址（32 位系统占 4 字节，64 位系统占 8 字节）。通过解引用操作符&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;*&lt;/code&gt;，可以访问指针指向的内存数据；通过修改指针本身的值，可以让它指向不同的内存地址。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;核心特征&lt;/span&gt;：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;有自己的内存空间；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;可以为空（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;NULL&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;nullptr&lt;/code&gt;）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;可以被重新赋值指向其他地址；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;支持多级指针（如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int** p&lt;/code&gt;，指向指针的指针）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 引用：“变量的别名”&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;引用是某一变量的&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;别名（Alias）&lt;/span&gt;，它本身不占用独立内存空间（编译器层面会复用原变量地址），必须在定义时初始化，且一旦绑定某个变量，就无法再指向其他变量。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;核心特征&lt;/span&gt;：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;无独立内存，本质是 “被绑定变量的地址别名”；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;定义时必须初始化（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int&amp;amp; ref;&lt;/code&gt;&amp;nbsp;编译报错）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;不能为 NULL；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;无法被重新绑定，一生只关联一个变量。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、语法对比：从定义到使用，一眼看清差异&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;我们通过一个简单示例，对比引用与指针的基础语法：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1yzr4ir&quot; data-popupid=&quot;1yzr4ir&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;11i3apb&quot; data-popupid=&quot;11i3apb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fpo43ij&quot; data-popupid=&quot;fpo43ij&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;p9n9lpu&quot; data-popupid=&quot;p9n9lpu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mvcxkwt&quot; data-popupid=&quot;mvcxkwt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#include&amp;nbsp;&amp;lt;iostream&amp;gt;using&amp;nbsp;namespace&amp;nbsp;std;int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;基础变量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;指针的定义与使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int*&amp;nbsp;p&amp;nbsp;=&amp;nbsp;&amp;amp;a;&amp;nbsp;&amp;nbsp;//&amp;nbsp;定义指针p，指向a的地址
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*p&amp;nbsp;=&amp;nbsp;20;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;解引用：修改p指向的内存数据（a的值变为20）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;指针操作后a=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：20

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;b&amp;nbsp;=&amp;nbsp;30;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p&amp;nbsp;=&amp;nbsp;&amp;amp;b;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;指针可以重新指向b的地址
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*p&amp;nbsp;=&amp;nbsp;40;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;指针指向b后，b=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;b&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：40

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;引用的定义与使用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;amp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;a;&amp;nbsp;//&amp;nbsp;定义引用ref，作为a的别名（必须初始化）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;50;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;直接修改ref，等价于修改a（a的值变为50）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;引用操作后a=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：50

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;b;&amp;nbsp;//&amp;nbsp;注意：这不是重新绑定，而是把b的值赋给a（a变为30）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;int&amp;amp;&amp;nbsp;ref2;&amp;nbsp;//&amp;nbsp;编译报错：引用必须初始化

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;核心语法差异表&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;维度&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;指针&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;引用&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;定义语法&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;类型* 变量名 = &amp;amp;目标&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;类型&amp;amp; 变量名 = 目标&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;初始化要求&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;可延迟初始化（允许&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;int* p;&lt;/code&gt;）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;必须初始化（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;int&amp;amp; ref;&lt;/code&gt;&amp;nbsp;报错）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;空值支持&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;可以为&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;NULL&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;nullptr&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;不允许为空&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;重新指向&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;可以指向其他变量&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;无法重新绑定&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;访问数据&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;需要解引用（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;*p&lt;/code&gt;）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;直接使用（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;ref&lt;/code&gt;）&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;多级操作&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;支持多级指针（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;int** p&lt;/code&gt;）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;无多级引用&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、底层原理：引用真的 “不占内存” 吗？&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;很多初学者会误以为 “引用完全不占内存”，但实际上：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;语法层面&lt;/span&gt;：C++ 标准规定引用是变量的别名，不占用独立内存；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;编译器实现层面&lt;/span&gt;：引用本质是 “只读的指针”—— 编译器会为引用分配内存（存储目标变量的地址），但禁止程序员修改这个地址（因此无法重新绑定）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;比如以下代码：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;doxk7ut&quot; data-popupid=&quot;doxk7ut&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dlpdmpd&quot; data-popupid=&quot;dlpdmpd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qv0cfsl&quot; data-popupid=&quot;qv0cfsl&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zyl90nr&quot; data-popupid=&quot;zyl90nr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jvmvhog&quot; data-popupid=&quot;jvmvhog&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10;int&amp;amp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;a;&amp;nbsp;//&amp;nbsp;编译器底层等价于：int*&amp;nbsp;const&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;&amp;amp;a;ref&amp;nbsp;=&amp;nbsp;20;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;等价于：*ref&amp;nbsp;=&amp;nbsp;20;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int* const ref&lt;/code&gt;&amp;nbsp;是 “常量指针”：指针本身的值（指向的地址）不可改，对应引用 “无法重新绑定”；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;引用的语法糖：编译器帮我们省略了&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;*&lt;/code&gt;解引用操作，让代码更简洁。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;blockquote class=&quot;auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0px 0px 5.45455px; border-style: solid; border-top-color: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: rgb(208, 215, 222); border-image: initial; margin: 12px 0px; padding: 0px 24px; font-size: 24px; font-weight: 600; line-height: 36px; --md-box-samantha-normal-text-color: rgba(0,0,0,.55); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 36px; font-weight: 400; overflow-anchor: auto;&quot;&gt;注意：这只是编译器的实现逻辑，并非 C++ 标准规定 —— 标准仅定义引用的行为，不限制实现方式。&lt;/div&gt;&lt;/blockquote&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、实战场景：什么时候用引用？什么时候用指针？&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;引用和指针的选择，核心看 “场景需求”，以下是高频场景的最佳实践：&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 1：函数参数传递（最核心的使用场景）&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;优先用引用的情况：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;需修改实参的值，且实参不可能为空；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;避免值传递的拷贝开销（如传递大对象、自定义类）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;追求代码简洁性（无需解引用）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：交换两个整数（引用版）&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;t1tu9f6&quot; data-popupid=&quot;t1tu9f6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ha9ts6v&quot; data-popupid=&quot;ha9ts6v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vbo9xme&quot; data-popupid=&quot;vbo9xme&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bv0ncqm&quot; data-popupid=&quot;bv0ncqm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1bt5rl5&quot; data-popupid=&quot;1bt5rl5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;引用版：简洁、无拷贝、实参不能为空void&amp;nbsp;swap(int&amp;amp;&amp;nbsp;x,&amp;nbsp;int&amp;amp;&amp;nbsp;y)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;temp&amp;nbsp;=&amp;nbsp;x;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x&amp;nbsp;=&amp;nbsp;y;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;y&amp;nbsp;=&amp;nbsp;temp;}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10,&amp;nbsp;b&amp;nbsp;=&amp;nbsp;20;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;swap(a,&amp;nbsp;b);&amp;nbsp;//&amp;nbsp;直接传变量，无需取地址
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;,&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;b&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：20,10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;必须用指针的情况：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;实参可能为空（需处理&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;nullptr&lt;/code&gt;）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;需在函数内修改指针指向（如动态分配内存、链表操作）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;兼容 C 语言代码（C 语言无引用）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：修改指针指向（指针版）&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2v275bt&quot; data-popupid=&quot;2v275bt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dm7efyq&quot; data-popupid=&quot;dm7efyq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;u9i42tw&quot; data-popupid=&quot;u9i42tw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ohw8sfx&quot; data-popupid=&quot;ohw8sfx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9y3lvtt&quot; data-popupid=&quot;9y3lvtt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;指针版：可以修改指针指向，支持空值void&amp;nbsp;reset(int*&amp;amp;&amp;nbsp;p)&amp;nbsp;{&amp;nbsp;//&amp;nbsp;注意：这里用引用接收指针，否则修改的是副本
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;释放原有内存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p&amp;nbsp;=&amp;nbsp;new&amp;nbsp;int(100);&amp;nbsp;//&amp;nbsp;重新指向新内存}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int*&amp;nbsp;p&amp;nbsp;=&amp;nbsp;new&amp;nbsp;int(10);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reset(p);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;*p&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;delete&amp;nbsp;p;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;特殊：const 引用（只读引用）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如果不需要修改实参，仅想避免拷贝，优先用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;const&lt;/code&gt;引用：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uitz3t5&quot; data-popupid=&quot;uitz3t5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e02qnnz&quot; data-popupid=&quot;e02qnnz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;m86s90w&quot; data-popupid=&quot;m86s90w&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zpcsyz8&quot; data-popupid=&quot;zpcsyz8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gai56nx&quot; data-popupid=&quot;gai56nx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;const引用：禁止修改实参，支持临时变量（如字面量）void&amp;nbsp;print(const&amp;nbsp;string&amp;amp;&amp;nbsp;str)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;str&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(&amp;quot;Hello&amp;quot;);&amp;nbsp;//&amp;nbsp;临时字符串自动绑定到const引用，合法
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;s&amp;nbsp;=&amp;nbsp;&amp;quot;World&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(s);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;无拷贝，高效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 2：函数返回值&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;优先用引用的情况：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;返回函数内已存在的变量（如类的成员变量），且确保变量生命周期足够长；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;支持链式调用（如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;cout &amp;lt;&amp;lt; a &amp;lt;&amp;lt; b&lt;/code&gt;、&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;string::operator+=&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;示例：类成员变量的引用返回&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r8tek65&quot; data-popupid=&quot;r8tek65&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xsntogl&quot; data-popupid=&quot;xsntogl&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uy4tz6x&quot; data-popupid=&quot;uy4tz6x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5sd38x0&quot; data-popupid=&quot;5sd38x0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;quitpg7&quot; data-popupid=&quot;quitpg7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;MyClass&amp;nbsp;{private:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;value&amp;nbsp;=&amp;nbsp;0;public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;返回引用：允许外部修改成员变量，无拷贝
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;amp;&amp;nbsp;getValue()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;value;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;MyClass&amp;nbsp;obj;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;obj.getValue()&amp;nbsp;=&amp;nbsp;100;&amp;nbsp;//&amp;nbsp;链式修改：等价于obj.value&amp;nbsp;=&amp;nbsp;100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;obj.getValue()&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;必须用指针的情况：&lt;/h4&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;返回动态分配的内存（如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;new int(10)&lt;/code&gt;）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;返回值可能为空（需返回&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;nullptr&lt;/code&gt;）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;避免返回局部变量的引用（局部变量生命周期结束，引用失效）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;⚠️ 禁忌：不要返回局部变量的引用 / 指针&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wlazyk0&quot; data-popupid=&quot;wlazyk0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8qx9g4v&quot; data-popupid=&quot;8qx9g4v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;55and63&quot; data-popupid=&quot;55and63&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vfacykr&quot; data-popupid=&quot;vfacykr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3nsuz51&quot; data-popupid=&quot;3nsuz51&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;错误示例：局部变量a在函数结束后销毁，返回的引用/指针失效int&amp;amp;&amp;nbsp;badRef()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;a;&amp;nbsp;//&amp;nbsp;编译可能通过，但运行时未定义行为}int*&amp;nbsp;badPtr()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;amp;a;&amp;nbsp;//&amp;nbsp;同理，指针指向已释放的栈内存}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 3：动态内存管理&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;动态内存分配 / 释放（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;new&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;delete&lt;/code&gt;）必须用指针：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;skajg19&quot; data-popupid=&quot;skajg19&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;aon3l4e&quot; data-popupid=&quot;aon3l4e&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ac9epfd&quot; data-popupid=&quot;ac9epfd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nhwtek5&quot; data-popupid=&quot;nhwtek5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xxd3z1w&quot; data-popupid=&quot;xxd3z1w&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;动态分配数组，只能用指针int*&amp;nbsp;arr&amp;nbsp;=&amp;nbsp;new&amp;nbsp;int[5]{1,2,3,4,5};delete[]&amp;nbsp;arr;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 4：链表 / 树等数据结构&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;链表节点的指针域必须用指针（需指向后续节点，支持空值）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;28gz67n&quot; data-popupid=&quot;28gz67n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wwr1pqd&quot; data-popupid=&quot;wwr1pqd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4ebxgqg&quot; data-popupid=&quot;4ebxgqg&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;m60sfho&quot; data-popupid=&quot;m60sfho&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;j9g49ic&quot; data-popupid=&quot;j9g49ic&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;struct&amp;nbsp;ListNode&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;val;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ListNode*&amp;nbsp;next;&amp;nbsp;//&amp;nbsp;指针：指向Next节点，最后一个节点为nullptr
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ListNode(int&amp;nbsp;x)&amp;nbsp;:&amp;nbsp;val(x),&amp;nbsp;next(nullptr)&amp;nbsp;{}};&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、避坑指南：引用与指针的常见错误&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 引用的 “重新绑定” 误区&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;引用无法重新绑定，看似 “重新赋值” 的操作实际是修改原变量：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jb537k9&quot; data-popupid=&quot;jb537k9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f9zjwjb&quot; data-popupid=&quot;f9zjwjb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uppyzrl&quot; data-popupid=&quot;uppyzrl&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3l6lmr4&quot; data-popupid=&quot;3l6lmr4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8u89p9a&quot; data-popupid=&quot;8u89p9a&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;int&amp;nbsp;a&amp;nbsp;=&amp;nbsp;10,&amp;nbsp;b&amp;nbsp;=&amp;nbsp;20;int&amp;amp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;a;ref&amp;nbsp;=&amp;nbsp;b;&amp;nbsp;//&amp;nbsp;不是绑定b，而是把b的值赋给a（a变为20）cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出：20&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 空指针解引用（最常见的运行时错误）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;指针未初始化或指向空时，解引用会导致程序崩溃：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pz2nn8k&quot; data-popupid=&quot;pz2nn8k&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mbpk5bk&quot; data-popupid=&quot;mbpk5bk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;utmgfk2&quot; data-popupid=&quot;utmgfk2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2jtgq2r&quot; data-popupid=&quot;2jtgq2r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;x00x2eb&quot; data-popupid=&quot;x00x2eb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;int*&amp;nbsp;p&amp;nbsp;=&amp;nbsp;nullptr;//&amp;nbsp;*p&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;运行时崩溃：空指针解引用//&amp;nbsp;解决：先判断指针是否为空if&amp;nbsp;(p&amp;nbsp;!=&amp;nbsp;nullptr)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;*p&amp;nbsp;=&amp;nbsp;10;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 返回局部变量的引用 / 指针&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;如前文所述，局部变量存储在栈上，函数结束后内存释放，引用 / 指针变为 “野引用 / 野指针”，访问时触发未定义行为。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. const 引用与临时变量&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;const&lt;/code&gt;引用可以绑定临时变量（如字面量），但非 const 引用不行：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;79ytpci&quot; data-popupid=&quot;79ytpci&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;sfe77m2&quot; data-popupid=&quot;sfe77m2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bewmyt3&quot; data-popupid=&quot;bewmyt3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;o0urj1q&quot; data-popupid=&quot;o0urj1q&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bhfafvo&quot; data-popupid=&quot;bhfafvo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;int&amp;amp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;编译报错：非const引用不能绑定临时变量const&amp;nbsp;int&amp;amp;&amp;nbsp;ref&amp;nbsp;=&amp;nbsp;10;&amp;nbsp;//&amp;nbsp;合法：编译器会创建临时变量存储10，ref绑定它&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、总结：引用与指针的核心取舍&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;选择引用&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;选择指针&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;追求代码简洁、直观&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;需处理空值、动态指向&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;实参 / 返回值不可能为空&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;实参 / 返回值可能为空&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;无需重新绑定目标变量&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;需修改指向的目标变量&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;函数参数 / 返回值避免拷贝&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;动态内存管理、兼容 C 语言&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;核心口诀&lt;/span&gt;：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;能用人引用，就用引用（简洁、安全）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;必须用指针时，才用指针（空值、动态指向）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;只读场景用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;const&lt;/code&gt;引用（高效、支持临时变量）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;引用和指针是 C++ 的 “双刃剑”：用对了能大幅提升代码效率和可读性，用错了则会导致内存泄漏、野指针 / 野引用等难以调试的问题。掌握二者的本质差异和适用场景，是进阶 C++ 程序员的必经之路。&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 05 Dec 2025 14:37:34 +0800</pubDate></item><item><title>吃透 C++ 函数重载：从原理到实战的全方位指南</title><link>https://songhongblog.top/?id=33</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在 C++ 编程中，函数重载是提升代码可读性与复用性的核心特性之一。它允许我们用相同的函数名，定义多个功能相似但参数不同的函数，让代码更符合自然语言的逻辑习惯。今天我们就从基础概念出发，一步步拆解函数重载的实现原理、使用规则与避坑技巧。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、什么是函数重载？一句话讲清核心&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;函数重载（Function Overloading）本质是 “&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;同名不同参&lt;/span&gt;的函数多态”—— 在同一作用域内，用相同的函数名定义多个函数，只要它们的&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;参数个数&lt;/span&gt;、&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;参数类型&lt;/span&gt;或&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;参数顺序&lt;/span&gt;不同，编译器就能识别并调用正确的函数。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;举个直观的例子，我们要实现 “加法” 功能：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;计算两个 int 的和：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int add(int a, int b)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;计算两个 double 的和：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;double add(double a, double b)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;计算三个 int 的和：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int add(int a, int b, int c)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;这三个函数名都是&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;add&lt;/code&gt;，但参数不同，编译器会根据调用时传入的实参，自动匹配对应的函数，这就是函数重载的核心价值。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、编译器如何 “区分” 同名函数？关键看 “函数签名”&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;很多初学者会疑惑：编译器怎么知道该调用哪个同名函数？答案是&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;函数签名（Function Signature）&lt;/span&gt;&amp;nbsp;—— 编译器通过特定规则生成的 “函数标识”，决定了两个函数是否属于重载关系。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 函数签名的构成（必须牢记）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;编译器判断函数是否重载，只看以下 3 个维度，&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;返回值类型不参与签名&lt;/span&gt;：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;参数个数：比如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(int a)&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(int a, int b)&lt;/code&gt;，个数不同 → 不同签名&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;参数类型：比如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(int a)&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(double a)&lt;/code&gt;，类型不同 → 不同签名&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;参数顺序：比如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(int a, double b)&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add(double a, int b)&lt;/code&gt;，顺序不同 → 不同签名&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 常见误区：这些情况不算重载！&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;以下两种情况，看似 “不同”，但编译器会判定为 “重复定义”，直接报错：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;仅返回值不同：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int add(int a)&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;double add(int a)&lt;/code&gt;&amp;nbsp;→ 签名相同，不是重载&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;仅参数名不同：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int add(int a, int b)&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;int add(int x, int y)&lt;/code&gt;&amp;nbsp;→ 签名相同，不是重载&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、函数重载的底层原理：名字修饰（Name Mangling）&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;C 语言不支持函数重载，但 C++ 支持，核心原因是编译器的 “&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;名字修饰&lt;/span&gt;” 机制 —— 编译阶段，编译器会根据函数签名，将函数名 “改写” 成唯一的标识符（不同编译器规则不同，以 GCC 为例）。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;比如以下三个&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;add&lt;/code&gt;函数：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -428.214px; padding: 0px; max-width: 1649.45px; width: 1649.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 428.214px; max-width: 100%; width: 1649.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;原函数名&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;函数签名&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;GCC 编译器修饰后名字&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;add(int, int)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;int+int&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;_Z3addii&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;add(double, double)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;double+double&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;_Z3adddd&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;add(int, int, int)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;int+int+int&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; color: rgb(0, 0, 0); overflow-anchor: auto;&quot;&gt;_Z3addiii&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;修饰规则解析：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;_Z&lt;/code&gt;是前缀，&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;3&lt;/code&gt;表示原函数名长度（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;add&lt;/code&gt;是 3 个字符），&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;ii&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;dd&lt;/code&gt;表示参数类型（i=int，d=double）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;核心作用：通过修饰，同名函数变成了不同的标识符，链接器就能准确找到对应的函数实现。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、实战：函数重载的使用场景与示例&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;函数重载在实际开发中应用极广，以下是 3 个高频场景及完整代码示例：&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 1：处理不同类型的参数&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;比如实现 “打印” 功能，支持 int、double、字符串三种类型：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f5dkrcv&quot; data-popupid=&quot;f5dkrcv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uthnith&quot; data-popupid=&quot;uthnith&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3nxhvvj&quot; data-popupid=&quot;3nxhvvj&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;emwir7u&quot; data-popupid=&quot;emwir7u&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;anqjuxs&quot; data-popupid=&quot;anqjuxs&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; tabindex=&quot;0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#include&amp;nbsp;&amp;lt;iostream&amp;gt;#include&amp;nbsp;&amp;lt;string&amp;gt;using&amp;nbsp;namespace&amp;nbsp;std;//&amp;nbsp;重载1：打印intvoid&amp;nbsp;print(int&amp;nbsp;num)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;整数：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;num&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}//&amp;nbsp;重载2：打印doublevoid&amp;nbsp;print(double&amp;nbsp;num)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;小数：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;num&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}//&amp;nbsp;重载3：打印stringvoid&amp;nbsp;print(string&amp;nbsp;str)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;字符串：&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;str&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(10);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用print(int)&amp;nbsp;→&amp;nbsp;输出“整数：10”
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(3.14);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用print(double)&amp;nbsp;→&amp;nbsp;输出“小数：3.14”
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(&amp;quot;Hello&amp;quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用print(string)&amp;nbsp;→&amp;nbsp;输出“字符串：Hello”
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 2：处理不同个数的参数&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;比如实现 “求最大值”，支持 2 个或 3 个 int 的比较：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mv3ba18&quot; data-popupid=&quot;mv3ba18&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kjia99g&quot; data-popupid=&quot;kjia99g&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5no3chg&quot; data-popupid=&quot;5no3chg&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;a3omipd&quot; data-popupid=&quot;a3omipd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zpx5oly&quot; data-popupid=&quot;zpx5oly&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;求2个int的最大值int&amp;nbsp;max(int&amp;nbsp;a,&amp;nbsp;int&amp;nbsp;b)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;a&amp;nbsp;&amp;gt;&amp;nbsp;b&amp;nbsp;?&amp;nbsp;a&amp;nbsp;:&amp;nbsp;b;}//&amp;nbsp;求3个int的最大值（复用2个参数的版本）int&amp;nbsp;max(int&amp;nbsp;a,&amp;nbsp;int&amp;nbsp;b,&amp;nbsp;int&amp;nbsp;c)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;max(max(a,&amp;nbsp;b),&amp;nbsp;c);&amp;nbsp;//&amp;nbsp;嵌套调用max(int,&amp;nbsp;int)}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;max(5,&amp;nbsp;8)&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;输出8
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;max(3,&amp;nbsp;9,&amp;nbsp;6)&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;//&amp;nbsp;输出9
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;场景 3：结合默认参数（注意避坑）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;默认参数可以和重载结合，但要避免 “二义性”（编译器无法确定调用哪个函数）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;na9xbvq&quot; data-popupid=&quot;na9xbvq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;02pma1j&quot; data-popupid=&quot;02pma1j&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2echybn&quot; data-popupid=&quot;2echybn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;36dc4ft&quot; data-popupid=&quot;36dc4ft&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zb1h40f&quot; data-popupid=&quot;zb1h40f&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;重载1：2个参数，无默认值void&amp;nbsp;func(int&amp;nbsp;a,&amp;nbsp;int&amp;nbsp;b)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;a=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;,&amp;nbsp;b=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;b&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}//&amp;nbsp;重载2：1个参数，有默认值（注意：不要写成func(int&amp;nbsp;a=0)，会和重载1冲突）void&amp;nbsp;func(int&amp;nbsp;a)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;a=&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;func(10,&amp;nbsp;20);&amp;nbsp;//&amp;nbsp;调用func(int,&amp;nbsp;int)&amp;nbsp;→&amp;nbsp;正确
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;func(5);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用func(int)&amp;nbsp;→&amp;nbsp;正确
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;func();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;错误：若func(int&amp;nbsp;a=0)存在，编译器无法判断调用哪个
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、避坑指南：函数重载的 3 个常见问题&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 二义性调用：编译器 “懵了”&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;当传入的实参，能匹配多个重载函数时，会触发 “二义性错误”，比如：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2j2gdth&quot; data-popupid=&quot;2j2gdth&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;426xal2&quot; data-popupid=&quot;426xal2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gva6abo&quot; data-popupid=&quot;gva6abo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jcy4s69&quot; data-popupid=&quot;jcy4s69&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ia3pxoh&quot; data-popupid=&quot;ia3pxoh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;void&amp;nbsp;func(int&amp;nbsp;a,&amp;nbsp;double&amp;nbsp;b)&amp;nbsp;{}void&amp;nbsp;func(double&amp;nbsp;a,&amp;nbsp;int&amp;nbsp;b)&amp;nbsp;{}int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;错误：10是int，20是int，两个函数都能匹配（int可隐式转double）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;func(10,&amp;nbsp;20);&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;解决办法&lt;/span&gt;：显式转换参数类型，比如&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;func(10.0, 20)&lt;/code&gt;或&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;func(10, 20.0)&lt;/code&gt;。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 引用 /const 参数的重载陷阱&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;当函数参数是 “值传递”“引用”“const 引用” 时，重载规则容易混淆：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;void func(int a)&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;void func(int&amp;amp; a)&lt;/code&gt;：算重载（参数类型不同）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;void func(int&amp;amp; a)&lt;/code&gt;&amp;nbsp;和&amp;nbsp;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;void func(const int&amp;amp; a)&lt;/code&gt;：算重载（const 修饰不同）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;但调用时需注意：非 const 变量会优先匹配非 const 引用，const 变量只能匹配 const 引用。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 继承中的重载：子类会 “隐藏” 父类同名函数&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在继承中，子类的同名函数会&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;隐藏&lt;/span&gt;父类所有同名函数（不管参数是否不同），而非重载：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--cpp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7pwbkhs&quot; data-popupid=&quot;7pwbkhs&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;cpp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bnj7phu&quot; data-popupid=&quot;bnj7phu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;j9v6c58&quot; data-popupid=&quot;j9v6c58&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jmyq2uu&quot; data-popupid=&quot;jmyq2uu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8whaj59&quot; data-popupid=&quot;8whaj59&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-cpp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;class&amp;nbsp;Father&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;show(int&amp;nbsp;a)&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Father:&amp;nbsp;&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;a&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};class&amp;nbsp;Son&amp;nbsp;:&amp;nbsp;public&amp;nbsp;Father&amp;nbsp;{public:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;子类同名函数，隐藏父类的show(int)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;show()&amp;nbsp;{&amp;nbsp;cout&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;&amp;quot;Son&amp;quot;&amp;nbsp;&amp;lt;&amp;lt;&amp;nbsp;endl;&amp;nbsp;}};int&amp;nbsp;main()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Son&amp;nbsp;s;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s.show();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;正确：调用子类show()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;s.show(10);&amp;nbsp;//&amp;nbsp;错误：父类show(int)被隐藏，无法直接调用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;s.Father::show(10);&amp;nbsp;//&amp;nbsp;正确：显式指定父类作用域
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、总结：函数重载的核心要点&lt;/h2&gt;&lt;ol class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;定义条件&lt;/span&gt;：同一作用域、同名函数，参数个数 / 类型 / 顺序不同（返回值无关）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;底层原理&lt;/span&gt;：编译器通过 “名字修饰”，将同名函数转为唯一标识符。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;核心禁忌&lt;/span&gt;：避免二义性调用、注意继承中的函数隐藏、不依赖返回值区分重载。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;使用价值&lt;/span&gt;：减少函数名冗余（不用写 addInt、addDouble）、提升代码可读性与可维护性。&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;函数重载是 C++ 多态的基础之一，掌握它能让你的代码更简洁、更符合 C++ 的设计思想。在实际开发中，建议结合具体场景合理使用，同时避开二义性和继承隐藏的坑。&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 05 Dec 2025 14:37:01 +0800</pubDate></item><item><title>Java 整合 Redis：从配置到实战的完整指南</title><link>https://songhongblog.top/?id=32</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在 Java 开发中，Redis 作为高性能的键值数据库，常用于缓存、分布式锁、会话存储等场景。但很多开发者在配置 Redis 时，常会遇到连接池优化、集群适配、序列化异常等问题。本文基于 Spring Boot 2.x 生态，从环境搭建到进阶实战，带你一站式搞定 Redis 配置。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、环境准备：基础依赖与版本选择&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;首先要明确技术栈版本搭配，避免因版本冲突导致的隐藏问题。推荐使用 Spring Data Redis（封装性好）或原生 Jedis（灵活性高），以下是两种方案的 Maven 依赖配置。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 核心依赖引入&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;方案 1：Spring Data Redis（推荐，默认集成 Lettuce 客户端）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--xml hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pgux9su&quot; data-popupid=&quot;pgux9su&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;xml&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zizr9h3&quot; data-popupid=&quot;zizr9h3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0pmjekf&quot; data-popupid=&quot;0pmjekf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;04kvo7c&quot; data-popupid=&quot;04kvo7c&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f9vrjkn&quot; data-popupid=&quot;f9vrjkn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-xml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;!--&amp;nbsp;Spring&amp;nbsp;Data&amp;nbsp;Redis核心包&amp;nbsp;--&amp;gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;spring-boot-starter-data-redis&amp;lt;/artifactId&amp;gt;&amp;lt;/dependency&amp;gt;&amp;lt;!--&amp;nbsp;连接池依赖（Lettuce需此包优化性能）&amp;nbsp;--&amp;gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.apache.commons&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;commons-pool2&amp;lt;/artifactId&amp;gt;&amp;lt;/dependency&amp;gt;&amp;lt;!--&amp;nbsp;用于JSON序列化（解决默认JDK序列化可读性差问题）&amp;nbsp;--&amp;gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;com.fasterxml.jackson.core&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;jackson-databind&amp;lt;/artifactId&amp;gt;&amp;lt;/dependency&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方案 2：原生 Jedis 客户端（适合需自定义连接逻辑场景）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--xml hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4smy5vr&quot; data-popupid=&quot;4smy5vr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;xml&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zntn5l8&quot; data-popupid=&quot;zntn5l8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;v0j135i&quot; data-popupid=&quot;v0j135i&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8yng70m&quot; data-popupid=&quot;8yng70m&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qznzins&quot; data-popupid=&quot;qznzins&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-xml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;!--&amp;nbsp;Jedis核心依赖&amp;nbsp;--&amp;gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;redis.clients&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;jedis&amp;lt;/artifactId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;version&amp;gt;3.10.0&amp;lt;/version&amp;gt;&amp;nbsp;&amp;lt;!--&amp;nbsp;建议使用3.x及以上稳定版&amp;nbsp;--&amp;gt;&amp;lt;/dependency&amp;gt;&amp;lt;!--&amp;nbsp;连接池依赖&amp;nbsp;--&amp;gt;&amp;lt;dependency&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;groupId&amp;gt;org.apache.commons&amp;lt;/groupId&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;artifactId&amp;gt;commons-pool2&amp;lt;/artifactId&amp;gt;&amp;lt;/dependency&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 版本兼容性说明&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;Spring Boot 2.x 建议搭配 Redis 5.x/6.x（支持集群新特性）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lettuce 客户端默认支持异步操作，Jedis 需手动配置异步池。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;若使用 Redis 7.x，需确保 Spring Data Redis 版本≥2.7.0。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、核心配置：单机 Redis 实战&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;单机 Redis 是开发环境和小型项目的常用方案，重点关注连接池参数、序列化方式、超时时间这三个核心配置。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 配置文件（application.yml）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--yaml hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2pxhnqu&quot; data-popupid=&quot;2pxhnqu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;yaml&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5hzy13h&quot; data-popupid=&quot;5hzy13h&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;721qy90&quot; data-popupid=&quot;721qy90&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bsfn7i2&quot; data-popupid=&quot;bsfn7i2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mwlu1xu&quot; data-popupid=&quot;mwlu1xu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-yaml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;spring:
&amp;nbsp;&amp;nbsp;redis:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;基础连接信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host:&amp;nbsp;127.0.0.1&amp;nbsp;&amp;nbsp;#&amp;nbsp;Redis服务器IP
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port:&amp;nbsp;6379&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;端口（默认6379）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;123456&amp;nbsp;#&amp;nbsp;若未设置密码可省略
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;database:&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;数据库索引（0-15，默认0）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timeout:&amp;nbsp;3000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;连接超时时间（毫秒）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;Lettuce连接池配置（若用Jedis则替换为jedis:）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lettuce:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pool:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-active:&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大连接数（默认8）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-idle:&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大空闲连接数（默认8）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;min-idle:&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;最小空闲连接数（默认2）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-wait:&amp;nbsp;-1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大等待时间（-1表示无限制，单位毫秒）&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 序列化配置类（关键！避免乱码）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Spring Data Redis 默认使用 JDK 序列化，会导致 Redis 中存储的内容是乱码且占用空间大。下面配置 Jackson2JsonRedisSerializer，实现 JSON 格式序列化。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--java hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8egq4ak&quot; data-popupid=&quot;8egq4ak&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;java&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9dkpzbx&quot; data-popupid=&quot;9dkpzbx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9jfsr5n&quot; data-popupid=&quot;9jfsr5n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qiib6ku&quot; data-popupid=&quot;qiib6ku&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;iz7x56x&quot; data-popupid=&quot;iz7x56x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-java&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;org.springframework.context.annotation.Bean;import&amp;nbsp;org.springframework.context.annotation.Configuration;import&amp;nbsp;org.springframework.data.redis.connection.RedisConnectionFactory;import&amp;nbsp;org.springframework.data.redis.core.RedisTemplate;import&amp;nbsp;org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;import&amp;nbsp;org.springframework.data.redis.serializer.StringRedisSerializer;import&amp;nbsp;com.fasterxml.jackson.databind.ObjectMapper;import&amp;nbsp;com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;@Configurationpublic&amp;nbsp;class&amp;nbsp;RedisConfig&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Bean
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;RedisTemplate&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;nbsp;redisTemplate(RedisConnectionFactory&amp;nbsp;factory)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RedisTemplate&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;nbsp;template&amp;nbsp;=&amp;nbsp;new&amp;nbsp;RedisTemplate&amp;lt;&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.setConnectionFactory(factory);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;配置Key的序列化方式（String）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StringRedisSerializer&amp;nbsp;stringSerializer&amp;nbsp;=&amp;nbsp;new&amp;nbsp;StringRedisSerializer();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.setKeySerializer(stringSerializer);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.setHashKeySerializer(stringSerializer);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;配置Value的序列化方式（JSON）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Jackson2JsonRedisSerializer&amp;lt;Object&amp;gt;&amp;nbsp;jsonSerializer&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Jackson2JsonRedisSerializer&amp;lt;&amp;gt;(Object.class);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ObjectMapper&amp;nbsp;objectMapper&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ObjectMapper();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;解决Java&amp;nbsp;8日期（LocalDateTime等）序列化问题
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;objectMapper.registerModule(new&amp;nbsp;JavaTimeModule());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;jsonSerializer.setObjectMapper(objectMapper);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.setValueSerializer(jsonSerializer);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.setHashValueSerializer(jsonSerializer);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化模板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;template.afterPropertiesSet();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;template;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 简单使用示例&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;通过 RedisTemplate 操作 Redis，支持 String、Hash、List 等常见数据结构：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--java hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;cm493he&quot; data-popupid=&quot;cm493he&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;java&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9zus5bp&quot; data-popupid=&quot;9zus5bp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;48fyyjq&quot; data-popupid=&quot;48fyyjq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gibxhg6&quot; data-popupid=&quot;gibxhg6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;m6if3cw&quot; data-popupid=&quot;m6if3cw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-java&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;org.springframework.beans.factory.annotation.Autowired;import&amp;nbsp;org.springframework.data.redis.core.RedisTemplate;import&amp;nbsp;org.springframework.web.bind.annotation.GetMapping;import&amp;nbsp;org.springframework.web.bind.annotation.RestController;import&amp;nbsp;java.time.LocalDateTime;@RestControllerpublic&amp;nbsp;class&amp;nbsp;RedisDemoController&amp;nbsp;{

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@Autowired
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;RedisTemplate&amp;lt;String,&amp;nbsp;Object&amp;gt;&amp;nbsp;redisTemplate;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@GetMapping(&amp;quot;/setCache&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;String&amp;nbsp;setCache()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;1.&amp;nbsp;存储String类型（key:&amp;nbsp;user:1，value:&amp;nbsp;用户对象，过期时间5分钟）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;User&amp;nbsp;user&amp;nbsp;=&amp;nbsp;new&amp;nbsp;User(1L,&amp;nbsp;&amp;quot;张三&amp;quot;,&amp;nbsp;LocalDateTime.now());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redisTemplate.opsForValue().set(&amp;quot;user:1&amp;quot;,&amp;nbsp;user,&amp;nbsp;5,&amp;nbsp;java.util.concurrent.TimeUnit.MINUTES);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;2.&amp;nbsp;存储Hash类型（key:&amp;nbsp;user:info，hashKey:&amp;nbsp;name/age）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redisTemplate.opsForHash().put(&amp;quot;user:info&amp;quot;,&amp;nbsp;&amp;quot;name&amp;quot;,&amp;nbsp;&amp;quot;李四&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redisTemplate.opsForHash().put(&amp;quot;user:info&amp;quot;,&amp;nbsp;&amp;quot;age&amp;quot;,&amp;nbsp;25);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;缓存设置成功&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@GetMapping(&amp;quot;/getCache&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;User&amp;nbsp;getCache()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取String类型缓存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;(User)&amp;nbsp;redisTemplate.opsForValue().get(&amp;quot;user:1&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、进阶配置：Redis 集群（哨兵 / 分片）&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;生产环境中，单机 Redis 存在单点故障风险，通常会部署集群（哨兵模式或分片集群）。以下是两种集群的配置方案。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 哨兵模式配置（高可用，解决单点故障）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;哨兵模式通过监控主从节点，实现故障自动切换，适合数据量不大但需高可用的场景。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置文件（application.yml）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--yaml hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;p15f3j1&quot; data-popupid=&quot;p15f3j1&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;yaml&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6i2dqi0&quot; data-popupid=&quot;6i2dqi0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bqrz6jn&quot; data-popupid=&quot;bqrz6jn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ziqx33b&quot; data-popupid=&quot;ziqx33b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xudv7il&quot; data-popupid=&quot;xudv7il&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-yaml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;spring:
&amp;nbsp;&amp;nbsp;redis:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;123456
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timeout:&amp;nbsp;3000
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lettuce:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pool:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-active:&amp;nbsp;16
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-idle:&amp;nbsp;8
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;min-idle:&amp;nbsp;4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;哨兵配置
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sentinel:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;master:&amp;nbsp;mymaster&amp;nbsp;&amp;nbsp;#&amp;nbsp;主节点名称（需与Redis哨兵配置一致）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nodes:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;哨兵节点列表（IP:端口）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.100:26379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.101:26379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.102:26379&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 分片集群配置（水平扩容，支持海量数据）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分片集群将数据分散到多个节点，每个节点存储部分数据，适合数据量超过单机容量的场景。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置文件（application.yml）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--yaml hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kjeiato&quot; data-popupid=&quot;kjeiato&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;yaml&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ep8tb7r&quot; data-popupid=&quot;ep8tb7r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zo0kla7&quot; data-popupid=&quot;zo0kla7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kfv853j&quot; data-popupid=&quot;kfv853j&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;61nrwt2&quot; data-popupid=&quot;61nrwt2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-yaml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;spring:
&amp;nbsp;&amp;nbsp;redis:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password:&amp;nbsp;123456
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;timeout:&amp;nbsp;3000
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lettuce:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pool:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-active:&amp;nbsp;16
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-idle:&amp;nbsp;8
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;min-idle:&amp;nbsp;4
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;分片集群节点配置
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cluster:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nodes:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;所有集群节点（主从节点都需配置）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.100:6379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.101:6379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.102:6379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-&amp;nbsp;192.168.1.103:6379
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max-redirects:&amp;nbsp;3&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大重定向次数（默认3）&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、常见问题与优化技巧&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 连接池参数优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;max-active&lt;/span&gt;：根据并发量调整，建议设为&amp;nbsp;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;CPU核心数 * 2 + 1&lt;/code&gt;（如 8 核 CPU 设为 17）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;max-wait&lt;/span&gt;：非 - 1 时，避免线程无限等待（建议设为 1000 毫秒）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;min-idle&lt;/span&gt;：根据业务低谷期的连接需求设置，避免频繁创建 / 销毁连接。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 避免 RedisTemplate 线程安全问题&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;RedisTemplate 是线程安全的，无需每次使用时新建，直接注入即可。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;若自定义 RedisTemplate，需用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;@Bean&lt;/code&gt;注解交由 Spring 管理，避免重复创建。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 解决 LocalDateTime 序列化异常&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;需在 ObjectMapper 中注册&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;JavaTimeModule&lt;/code&gt;（如上文配置类所示），否则会报&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;JsonProcessingException&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;若使用 FastJSON 序列化，需添加&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;@JSONField(format = &amp;quot;yyyy-MM-dd HH:mm:ss&amp;quot;)&lt;/code&gt;注解。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、总结&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文从基础到进阶，覆盖了 Java 整合 Redis 的核心场景：单机配置解决开发需求，集群配置应对生产环境，序列化配置避免乱码问题。实际开发中，需根据业务规模（数据量、并发量）选择合适的方案，同时关注连接池优化和异常处理，才能让 Redis 真正发挥高性能优势。&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 02 Dec 2025 17:50:41 +0800</pubDate></item><item><title>PHP 整合 Redis：从基础配置到生产级优化全指南</title><link>https://songhongblog.top/?id=30</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Redis 作为高性能的键值数据库，是 PHP 开发中缓存、会话存储、分布式锁的首选方案。但很多开发者在配置 Redis 时，常遇到连接不稳定、序列化混乱、集群适配难等问题。本文基于 PHP 7.4 + 环境，从扩展安装、单机配置、集群适配到性能优化，带你一站式搞定 PHP+Redis 的全流程配置。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、环境准备：扩展安装与版本适配&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;PHP 操作 Redis 主要依赖&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;phpredis&lt;/code&gt;扩展（原生 C 扩展，性能最优），部分场景也可使用 Predis（纯 PHP 库，无需编译）。优先推荐&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;phpredis&lt;/code&gt;，以下是两种方案的安装与版本适配说明。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 核心扩展安装&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;方案 1：phpredis 扩展（推荐，高性能）&lt;/h4&gt;&lt;h5 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;方式 1：编译安装（适合自定义编译 PHP 的场景）&lt;/h5&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--bash hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;numplb3&quot; data-popupid=&quot;numplb3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;bash&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;l2gt8js&quot; data-popupid=&quot;l2gt8js&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1wvee0a&quot; data-popupid=&quot;1wvee0a&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;s6rnlas&quot; data-popupid=&quot;s6rnlas&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2184yn3&quot; data-popupid=&quot;2184yn3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-bash&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#&amp;nbsp;下载对应版本（建议5.3.7+，适配Redis&amp;nbsp;6.x/7.x）wget&amp;nbsp;https://pecl.php.net/get/redis-5.3.7.tgztar&amp;nbsp;-zxvf&amp;nbsp;redis-5.3.7.tgzcd&amp;nbsp;redis-5.3.7#&amp;nbsp;编译（指定php-config路径，根据实际安装目录调整）phpize
./configure&amp;nbsp;--with-php-config=/usr/local/php/bin/php-configmake&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;make&amp;nbsp;install#&amp;nbsp;配置php.ini（添加扩展）echo&amp;nbsp;&amp;quot;extension=redis.so&amp;quot;&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;/usr/local/php/etc/php.ini#&amp;nbsp;重启PHP-FPM或Apachesystemctl&amp;nbsp;restart&amp;nbsp;php-fpm&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h5 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方式 2：包管理器安装（适合 Linux 发行版）&lt;/h5&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--bash hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;inox0nv&quot; data-popupid=&quot;inox0nv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;bash&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nj1r1sm&quot; data-popupid=&quot;nj1r1sm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;cigv42s&quot; data-popupid=&quot;cigv42s&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;lyu7cjn&quot; data-popupid=&quot;lyu7cjn&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nnmvz4s&quot; data-popupid=&quot;nnmvz4s&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-bash&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#&amp;nbsp;CentOS/RHELyum&amp;nbsp;install&amp;nbsp;php-redis&amp;nbsp;-y#&amp;nbsp;Ubuntu/Debianapt&amp;nbsp;install&amp;nbsp;php-redis&amp;nbsp;-y#&amp;nbsp;验证安装是否成功php&amp;nbsp;-m&amp;nbsp;|&amp;nbsp;grep&amp;nbsp;redis&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方案 2：Predis（纯 PHP 库，无需编译）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;适合无法安装扩展的场景（如共享服务器），通过 Composer 安装：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--bash hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kryjq11&quot; data-popupid=&quot;kryjq11&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;bash&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;g9v61py&quot; data-popupid=&quot;g9v61py&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zj72d6b&quot; data-popupid=&quot;zj72d6b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hc1zj83&quot; data-popupid=&quot;hc1zj83&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;17y2hub&quot; data-popupid=&quot;17y2hub&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-bash&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;composer&amp;nbsp;require&amp;nbsp;predis/predis:^2.0&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 版本兼容性说明&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -288.214px; padding: 0px; max-width: 1369.45px; width: 1369.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 288.214px; max-width: 100%; width: 1369.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;PHP 版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;phpredis 推荐版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;Redis 服务端版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;备注&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;PHP 7.4+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;5.3.x+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;5.x/6.x/7.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;支持 Redis 集群、流（Stream）等新特性&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;PHP 8.0+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;6.0.x+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;6.x/7.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;适配 PHP 8 的类型特性&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;PHP 5.6（不推荐）&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;4.3.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;4.x/5.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;仅支持基础功能，无集群适配&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、基础配置：单机 Redis 实战&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;单机 Redis 是开发环境和小型项目的主流方案，重点关注连接参数、超时设置、序列化方式，避免常见的连接超时、数据乱码问题。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. phpredis 扩展配置（推荐）&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;核心连接与操作示例&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;j1zvehc&quot; data-popupid=&quot;j1zvehc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9jhp6z9&quot; data-popupid=&quot;9jhp6z9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;n8i4wt3&quot; data-popupid=&quot;n8i4wt3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;s69e9hx&quot; data-popupid=&quot;s69e9hx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fgxd32e&quot; data-popupid=&quot;fgxd32e&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?php//&amp;nbsp;1.&amp;nbsp;初始化Redis连接$redis&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Redis();//&amp;nbsp;2.&amp;nbsp;建立连接（支持TCP/UNIX&amp;nbsp;Socket）//&amp;nbsp;TCP连接（常用）$redis-&amp;gt;connect(&amp;#39;127.0.0.1&amp;#39;,&amp;nbsp;6379,&amp;nbsp;3);&amp;nbsp;//&amp;nbsp;主机、端口、超时时间（秒）//&amp;nbsp;UNIX&amp;nbsp;Socket连接（性能更高，需Redis开启socket配置）//&amp;nbsp;$redis-&amp;gt;connect(&amp;#39;unix:///var/run/redis/redis.sock&amp;#39;);//&amp;nbsp;3.&amp;nbsp;配置认证（若Redis设置密码）$redis-&amp;gt;auth(&amp;#39;123456&amp;#39;);//&amp;nbsp;4.&amp;nbsp;选择数据库（0-15，默认0）$redis-&amp;gt;select(0);//&amp;nbsp;5.&amp;nbsp;设置连接超时（可选，覆盖connect的超时参数）$redis-&amp;gt;setOption(Redis::OPT_READ_TIMEOUT,&amp;nbsp;3);//&amp;nbsp;==========&amp;nbsp;常用数据结构操作&amp;nbsp;==========//&amp;nbsp;1.&amp;nbsp;String类型（缓存用户信息，过期时间5分钟）$user&amp;nbsp;=&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;id&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;name&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;张三&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;create_time&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;date(&amp;#39;Y-m-d&amp;nbsp;H:i:s&amp;#39;)];//&amp;nbsp;序列化：推荐JSON（避免serialize()的兼容性问题）$redis-&amp;gt;set(&amp;#39;user:1&amp;#39;,&amp;nbsp;json_encode($user),&amp;nbsp;Redis::EX,&amp;nbsp;300);//&amp;nbsp;2.&amp;nbsp;获取String类型数据$userData&amp;nbsp;=&amp;nbsp;json_decode($redis-&amp;gt;get(&amp;#39;user:1&amp;#39;),&amp;nbsp;true);var_dump($userData);//&amp;nbsp;3.&amp;nbsp;Hash类型（存储用户多字段信息）$redis-&amp;gt;hSet(&amp;#39;user:info&amp;#39;,&amp;nbsp;&amp;#39;name&amp;#39;,&amp;nbsp;&amp;#39;李四&amp;#39;);$redis-&amp;gt;hSet(&amp;#39;user:info&amp;#39;,&amp;nbsp;&amp;#39;age&amp;#39;,&amp;nbsp;25);//&amp;nbsp;获取Hash所有字段$userInfo&amp;nbsp;=&amp;nbsp;$redis-&amp;gt;hGetAll(&amp;#39;user:info&amp;#39;);//&amp;nbsp;4.&amp;nbsp;List类型（消息队列示例）$redis-&amp;gt;lPush(&amp;#39;msg:queue&amp;#39;,&amp;nbsp;&amp;#39;订单创建通知&amp;#39;);$msg&amp;nbsp;=&amp;nbsp;$redis-&amp;gt;rPop(&amp;#39;msg:queue&amp;#39;);//&amp;nbsp;5.&amp;nbsp;关闭连接（可选，PHP结束会自动释放）$redis-&amp;gt;close();?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;配置优化：持久化连接（减少连接开销）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;频繁创建 / 销毁 Redis 连接会损耗性能，推荐使用持久化连接：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gr73289&quot; data-popupid=&quot;gr73289&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0dyryli&quot; data-popupid=&quot;0dyryli&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e2m6q1d&quot; data-popupid=&quot;e2m6q1d&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;73wj5rv&quot; data-popupid=&quot;73wj5rv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7nylbcm&quot; data-popupid=&quot;7nylbcm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?php//&amp;nbsp;使用pconnect建立持久化连接（参数与connect一致）$redis&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Redis();$redis-&amp;gt;pconnect(&amp;#39;127.0.0.1&amp;#39;,&amp;nbsp;6379,&amp;nbsp;3);&amp;nbsp;//&amp;nbsp;注意：持久化连接需配合PHP-FPM的pm参数优化，避免连接数耗尽?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. Predis 配置（无扩展场景）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ntrklcz&quot; data-popupid=&quot;ntrklcz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;y4wzlj0&quot; data-popupid=&quot;y4wzlj0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e2elpt6&quot; data-popupid=&quot;e2elpt6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;i9inget&quot; data-popupid=&quot;i9inget&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zma4rla&quot; data-popupid=&quot;zma4rla&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?phprequire&amp;nbsp;&amp;#39;vendor/autoload.php&amp;#39;;//&amp;nbsp;初始化客户端（支持单机、集群、哨兵）$client&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Predis\Client([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;scheme&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;tcp&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;host&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;127.0.0.1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;port&amp;#39;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&amp;nbsp;6379,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;password&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;database&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;0,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;timeout&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;3.0,&amp;nbsp;//&amp;nbsp;超时时间]);//&amp;nbsp;基本操作（与phpredis语法兼容）$client-&amp;gt;set(&amp;#39;site:name&amp;#39;,&amp;nbsp;&amp;#39;PHP中文网&amp;#39;,&amp;nbsp;&amp;#39;EX&amp;#39;,&amp;nbsp;300);echo&amp;nbsp;$client-&amp;gt;get(&amp;#39;site:name&amp;#39;);//&amp;nbsp;批量操作（提升性能）$client-&amp;gt;mset([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;key1&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;value1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;key2&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;value2&amp;#39;]);$values&amp;nbsp;=&amp;nbsp;$client-&amp;gt;mget([&amp;#39;key1&amp;#39;,&amp;nbsp;&amp;#39;key2&amp;#39;]);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、进阶配置：Redis 集群与哨兵模式&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;生产环境中，单机 Redis 存在单点故障风险，需部署集群或哨兵模式保障高可用。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 哨兵模式配置（高可用，解决单点故障）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;哨兵模式通过监控主从节点实现自动故障切换，适合数据量不大但需高可用的场景。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;phpredis 实现哨兵连接&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r62p27a&quot; data-popupid=&quot;r62p27a&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1t9gey0&quot; data-popupid=&quot;1t9gey0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;beqntzp&quot; data-popupid=&quot;beqntzp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1d9877b&quot; data-popupid=&quot;1d9877b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;p7s63xb&quot; data-popupid=&quot;p7s63xb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?php$redis&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Redis();//&amp;nbsp;连接哨兵（参数：哨兵地址数组、主节点名称、超时时间）$redis-&amp;gt;connectViaSentinel(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[[&amp;#39;192.168.1.100&amp;#39;,&amp;nbsp;26379],&amp;nbsp;[&amp;#39;192.168.1.101&amp;#39;,&amp;nbsp;26379]],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;mymaster&amp;#39;,&amp;nbsp;//&amp;nbsp;主节点名称（与Redis哨兵配置一致）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;//&amp;nbsp;超时时间);$redis-&amp;gt;auth(&amp;#39;123456&amp;#39;);$redis-&amp;gt;set(&amp;#39;test:sentinel&amp;#39;,&amp;nbsp;&amp;#39;success&amp;#39;);echo&amp;nbsp;$redis-&amp;gt;get(&amp;#39;test:sentinel&amp;#39;);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Predis 实现哨兵连接&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;l9azokv&quot; data-popupid=&quot;l9azokv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7uewu7r&quot; data-popupid=&quot;7uewu7r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wglmgd2&quot; data-popupid=&quot;wglmgd2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qmmy9su&quot; data-popupid=&quot;qmmy9su&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;meriyum&quot; data-popupid=&quot;meriyum&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?phprequire&amp;nbsp;&amp;#39;vendor/autoload.php&amp;#39;;$client&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Predis\Client([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;scheme&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;tcp&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;service&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;mymaster&amp;#39;,&amp;nbsp;//&amp;nbsp;主节点名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;sentinels&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&amp;#39;host&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;192.168.1.100&amp;#39;,&amp;nbsp;&amp;#39;port&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;26379],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&amp;#39;host&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;192.168.1.101&amp;#39;,&amp;nbsp;&amp;#39;port&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;26379],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;password&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;database&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;0,]);$client-&amp;gt;set(&amp;#39;test:sentinel:predis&amp;#39;,&amp;nbsp;&amp;#39;success&amp;#39;);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 分片集群配置（水平扩容，支持海量数据）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分片集群将数据分散到多个节点，适合数据量超过单机容量的场景（如电商商品缓存）。&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;phpredis 实现集群连接&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jj5o4ps&quot; data-popupid=&quot;jj5o4ps&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;re25nlq&quot; data-popupid=&quot;re25nlq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pmufjty&quot; data-popupid=&quot;pmufjty&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;b4rxn25&quot; data-popupid=&quot;b4rxn25&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6irtr2v&quot; data-popupid=&quot;6irtr2v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?php$redisCluster&amp;nbsp;=&amp;nbsp;new&amp;nbsp;RedisCluster(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;null,&amp;nbsp;//&amp;nbsp;集群名称（null即可）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;192.168.1.100:6379&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;192.168.1.101:6379&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;192.168.1.102:6379&amp;#39;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3,&amp;nbsp;//&amp;nbsp;连接超时
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3,&amp;nbsp;//&amp;nbsp;读取超时
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;false,&amp;nbsp;//&amp;nbsp;是否持久化连接
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;123456&amp;#39;&amp;nbsp;//&amp;nbsp;Redis密码);//&amp;nbsp;集群操作（与单机语法一致）$redisCluster-&amp;gt;set(&amp;#39;product:1001&amp;#39;,&amp;nbsp;json_encode([&amp;#39;name&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;小米手机&amp;#39;,&amp;nbsp;&amp;#39;price&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;1999]));$product&amp;nbsp;=&amp;nbsp;json_decode($redisCluster-&amp;gt;get(&amp;#39;product:1001&amp;#39;),&amp;nbsp;true);var_dump($product);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Predis 实现集群连接&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mkekkfi&quot; data-popupid=&quot;mkekkfi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ofb169y&quot; data-popupid=&quot;ofb169y&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kub8a8k&quot; data-popupid=&quot;kub8a8k&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;d626ty8&quot; data-popupid=&quot;d626ty8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kd5oni0&quot; data-popupid=&quot;kd5oni0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?phprequire&amp;nbsp;&amp;#39;vendor/autoload.php&amp;#39;;$client&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Predis\Client([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;cluster&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;redis&amp;#39;,&amp;nbsp;//&amp;nbsp;指定集群模式
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;nodes&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;tcp://192.168.1.100:6379&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;tcp://192.168.1.101:6379&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;tcp://192.168.1.102:6379&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;password&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;database&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;0,]);$client-&amp;gt;set(&amp;#39;product:1002&amp;#39;,&amp;nbsp;&amp;#39;华为手机&amp;#39;);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、生产级优化技巧&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 连接池优化（避免连接耗尽）&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;持久化连接 + PHP-FPM 参数调整&lt;/span&gt;：&lt;/p&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; font-size: 2px !important;&quot;&gt;&lt;/div&gt;&lt;p&gt;持久化连接（pconnect）需配合 PHP-FPM 的&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;pm.max_children&lt;/code&gt;和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;pm.max_requests&lt;/code&gt;，避免连接数超过 Redis 的&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;maxclients&lt;/code&gt;（默认 10000）。&lt;/p&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--ini hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 773.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;yrnafds&quot; data-popupid=&quot;yrnafds&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;ini&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;t09ar0n&quot; data-popupid=&quot;t09ar0n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fz9aa18&quot; data-popupid=&quot;fz9aa18&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;n0r0rdb&quot; data-popupid=&quot;n0r0rdb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wzbrsmo&quot; data-popupid=&quot;wzbrsmo&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-ini&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;;&amp;nbsp;php-fpm.conf示例配置pm&amp;nbsp;=&amp;nbsp;dynamicpm.max_children&amp;nbsp;=&amp;nbsp;50&amp;nbsp;;&amp;nbsp;最大子进程数（根据Redis&amp;nbsp;maxclients调整）pm.max_requests&amp;nbsp;=&amp;nbsp;1000&amp;nbsp;;&amp;nbsp;每个子进程处理1000次请求后重启，释放持久连接&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;span style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; font-weight: 700; line-height: 28px; overflow-anchor: auto;&quot;&gt;连接超时设置&lt;/span&gt;：必须设置超时时间（建议 2-3 秒），避免线程阻塞。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 数据序列化优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;避免使用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;serialize()&lt;/code&gt;：序列化结果不可读，且存在安全风险（反序列化漏洞）。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;推荐 JSON 序列化：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;json_encode()&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;json_decode()&lt;/code&gt;，需注意处理中文（添加&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;JSON_UNESCAPED_UNICODE&lt;/code&gt;）：&lt;/p&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 773.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e59o56n&quot; data-popupid=&quot;e59o56n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gl4w8pc&quot; data-popupid=&quot;gl4w8pc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kf32ad5&quot; data-popupid=&quot;kf32ad5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0z43fa5&quot; data-popupid=&quot;0z43fa5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;lrfrk02&quot; data-popupid=&quot;lrfrk02&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;$data&amp;nbsp;=&amp;nbsp;[&amp;#39;name&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;张三&amp;#39;,&amp;nbsp;&amp;#39;age&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;25];$redis-&amp;gt;set(&amp;#39;user:2&amp;#39;,&amp;nbsp;json_encode($data,&amp;nbsp;JSON_UNESCAPED_UNICODE));$user&amp;nbsp;=&amp;nbsp;json_decode($redis-&amp;gt;get(&amp;#39;user:2&amp;#39;),&amp;nbsp;true);&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 批量操作提升性能&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;mset()&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;mget()&lt;/code&gt;替代多次&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;set()&lt;/code&gt;/&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;get()&lt;/code&gt;，减少网络往返：&lt;/p&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 773.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4kccy83&quot; data-popupid=&quot;4kccy83&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vqni82p&quot; data-popupid=&quot;vqni82p&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wn4lstq&quot; data-popupid=&quot;wn4lstq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;idty0kk&quot; data-popupid=&quot;idty0kk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mraq3lb&quot; data-popupid=&quot;mraq3lb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;批量写入$redis-&amp;gt;mset([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;key1&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;val1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;key2&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;val2&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;key3&amp;#39;&amp;nbsp;=&amp;gt;&amp;nbsp;&amp;#39;val3&amp;#39;]);//&amp;nbsp;批量读取$values&amp;nbsp;=&amp;nbsp;$redis-&amp;gt;mget([&amp;#39;key1&amp;#39;,&amp;nbsp;&amp;#39;key2&amp;#39;,&amp;nbsp;&amp;#39;key3&amp;#39;]);&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 异常处理与重连机制&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;生产环境需捕获 Redis 连接异常，实现自动重连：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--php hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ykeki0x&quot; data-popupid=&quot;ykeki0x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;php&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0rxnu6h&quot; data-popupid=&quot;0rxnu6h&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2gu75em&quot; data-popupid=&quot;2gu75em&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;du5riov&quot; data-popupid=&quot;du5riov&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;uugpiv6&quot; data-popupid=&quot;uugpiv6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-php&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;&amp;lt;?phpfunction&amp;nbsp;getRedisInstance()&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;static&amp;nbsp;$redis&amp;nbsp;=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;($redis&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;$redis-&amp;gt;isConnected())&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;$redis;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$redis&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Redis();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$redis-&amp;gt;pconnect(&amp;#39;127.0.0.1&amp;#39;,&amp;nbsp;6379,&amp;nbsp;3);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$redis-&amp;gt;auth(&amp;#39;123456&amp;#39;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$redis-&amp;gt;select(0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;$redis;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;catch&amp;nbsp;(RedisException&amp;nbsp;$e)&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;记录日志
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;error_log(&amp;quot;Redis连接失败：&amp;quot;&amp;nbsp;.&amp;nbsp;$e-&amp;gt;getMessage());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw&amp;nbsp;new&amp;nbsp;Exception(&amp;quot;Redis服务不可用&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}//&amp;nbsp;使用示例$redis&amp;nbsp;=&amp;nbsp;getRedisInstance();$redis-&amp;gt;set(&amp;#39;test:reconnect&amp;#39;,&amp;nbsp;&amp;#39;success&amp;#39;);?&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、常见问题排查&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 连接超时 / 拒绝连接&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;检查 Redis 服务是否启动：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;systemctl status redis&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查 Redis 绑定 IP：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;bind 0.0.0.0&lt;/code&gt;（允许外部访问），关闭保护模式：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;protected-mode no&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查防火墙：开放 6379 端口（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;firewall-cmd --add-port=6379/tcp --permanent&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. phpredis 扩展加载失败&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;确认扩展路径是否正确：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;php -i | grep extension_dir&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查 PHP 版本与扩展版本是否匹配（如 PHP 8.0 需用 6.x 版本扩展）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 集群操作报 MOVED 错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;确保使用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;RedisCluster&lt;/code&gt;类而非&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;Redis&lt;/code&gt;类，集群节点需全部配置。&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查 Redis 集群是否正常：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;redis-cli --cluster check 192.168.1.100:6379&lt;/code&gt;。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、总结&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文覆盖了 PHP 整合 Redis 的全场景：基础扩展安装满足开发需求，哨兵 / 集群配置应对生产高可用，优化技巧解决性能与稳定性问题。实际开发中，需根据业务规模选择方案 —— 小项目用单机 + 持久化连接，中大型项目用哨兵 / 集群，同时做好异常处理和批量操作，才能让 Redis 发挥最大性能优势。&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 02 Dec 2025 17:50:05 +0800</pubDate></item><item><title>python整合 Redis：从基础配置到生产级优化全指南</title><link>https://songhongblog.top/?id=31</link><description>&lt;h1 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 20px; line-height: 30px; font-family: Montserrat; overflow-anchor: auto; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 0px !important;&quot;&gt;&lt;br/&gt;&lt;/h1&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Redis 作为高性能的键值数据库，是 Python 开发中缓存、消息队列、分布式锁的核心组件。不管是 Web 框架（Django/Flask）中的缓存优化，还是大数据场景下的临时数据存储，Python+Redis 的组合都能显著提升系统性能。本文基于 Python 3.8 + 环境，从客户端选型、单机配置、集群适配到性能优化，带你一站式搞定 Python 操作 Redis 的全流程配置。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、环境准备：客户端选型与安装&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Python 操作 Redis 主流有两个客户端：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redis-py&lt;/code&gt;（官方推荐，原生高性能）和&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redislite&lt;/code&gt;（轻量级，无需独立部署 Redis 服务）。优先选择&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redis-py&lt;/code&gt;（适配生产环境），以下是详细安装与版本适配说明。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 核心客户端安装&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;方案 1：redis-py（推荐，生产环境首选）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redis-py&lt;/code&gt;是 Redis 官方维护的 Python 客户端，支持 Redis 全特性（集群、哨兵、管道等），通过 pip 安装：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--bash hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;z0xh56c&quot; data-popupid=&quot;z0xh56c&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;bash&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nx3r0bs&quot; data-popupid=&quot;nx3r0bs&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r0xzfbi&quot; data-popupid=&quot;r0xzfbi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zzqi8r9&quot; data-popupid=&quot;zzqi8r9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;tyatq9k&quot; data-popupid=&quot;tyatq9k&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-bash&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#&amp;nbsp;基础版（适配Redis&amp;nbsp;5.x/6.x）pip&amp;nbsp;install&amp;nbsp;redis==4.5.5#&amp;nbsp;若需适配Redis&amp;nbsp;7.x，安装最新稳定版pip&amp;nbsp;install&amp;nbsp;redis&amp;gt;=5.0.0#&amp;nbsp;验证安装python&amp;nbsp;-c&amp;nbsp;&amp;quot;import&amp;nbsp;redis;&amp;nbsp;print(redis.__version__)&amp;quot;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;方案 2：redislite（轻量级，开发 / 测试场景）&lt;/h4&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;无需单独部署 Redis 服务，内置轻量级 Redis 实例，适合本地调试：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--bash hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;i2lf8yr&quot; data-popupid=&quot;i2lf8yr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;bash&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gkwr5xb&quot; data-popupid=&quot;gkwr5xb&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5vodkz9&quot; data-popupid=&quot;5vodkz9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4cmw026&quot; data-popupid=&quot;4cmw026&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gkuswp2&quot; data-popupid=&quot;gkuswp2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-bash&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;pip&amp;nbsp;install&amp;nbsp;redislite&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 版本兼容性说明&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br mdbox-table-root table-container-cYf_5N&quot; data-scroll-inline-overflow=&quot;false&quot; data-scroll-inline-at-start=&quot;true&quot; data-scroll-inline-start-overflow=&quot;false&quot; data-scroll-inline-at-end=&quot;true&quot; data-scroll-inline-end-overflow=&quot;false&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px 0px -4px -288.214px; padding: 0px; max-width: 1369.45px; width: 1369.45px; position: relative; --table-inline-padding: 48px; --table-width: calc(100cqi - 48px*2); overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;table-scroll-container-Gyf4hQ mdbox-table-scroll-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 0px 12px 288.214px; max-width: 100%; width: 1369.45px; overflow: auto; scrollbar-color: rgb(204, 204, 204) rgba(0, 0, 0, 0); overflow-anchor: auto;&quot;&gt;&lt;table width=&quot;NaN&quot;&gt;&lt;thead style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(242, 242, 242); font-weight: 600; line-height: normal;&quot; class=&quot;firstRow&quot;&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;Python 版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;redis-py 推荐版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;Redis 服务端版本&lt;/th&gt;&lt;th style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto;&quot;&gt;核心特性支持&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;3.8+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;4.5.x+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;5.x/6.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;集群、哨兵、管道&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;3.10+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;5.0.x+&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;6.x/7.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;Redis 7.x 新指令、异步客户端&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0px 0px; border-style: solid; border-top-color: rgba(0, 0, 0, 0.08); border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; margin: 0px; padding: 0px; overflow-anchor: auto; line-height: normal;&quot;&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;3.7-&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;3.5.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 0.909091px 0px 0px; border-top-style: initial; border-bottom-style: initial; border-left-style: initial; border-top-color: initial; border-right-color: rgba(0, 0, 0, 0.08); border-bottom-color: initial; border-left-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;4.x/5.x&lt;/td&gt;&lt;td style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px; border-style: initial; border-color: initial; margin: 0px; padding: 12px 18px; line-height: 28px; max-width: 448px; overflow-anchor: auto; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;基础功能，无异步支持&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、基础配置：单机 Redis 实战&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;单机 Redis 是开发环境和小型项目的主流方案，重点关注连接参数、序列化、连接池优化，避免频繁创建连接导致性能损耗。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 基础连接与操作示例&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;km8gies&quot; data-popupid=&quot;km8gies&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3h8tog7&quot; data-popupid=&quot;3h8tog7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;i1roheq&quot; data-popupid=&quot;i1roheq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5l01uun&quot; data-popupid=&quot;5l01uun&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0hs3vg4&quot; data-popupid=&quot;0hs3vg4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redisimport&amp;nbsp;jsonfrom&amp;nbsp;datetime&amp;nbsp;import&amp;nbsp;datetime#&amp;nbsp;1.&amp;nbsp;初始化Redis连接（基础版）r&amp;nbsp;=&amp;nbsp;redis.Redis(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host=&amp;#39;127.0.0.1&amp;#39;,&amp;nbsp;&amp;nbsp;#&amp;nbsp;Redis服务器IP
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port=6379,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;端口（默认6379）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,&amp;nbsp;#&amp;nbsp;无密码则省略
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db=0,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;数据库索引（0-15，默认0）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,&amp;nbsp;&amp;nbsp;#&amp;nbsp;自动解码为字符串（避免b&amp;#39;xxx&amp;#39;字节类型）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_timeout=3,&amp;nbsp;&amp;nbsp;#&amp;nbsp;连接/读取超时时间（秒）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_connect_timeout=3&amp;nbsp;#&amp;nbsp;连接建立超时时间（秒）)#&amp;nbsp;==========&amp;nbsp;常用数据结构操作&amp;nbsp;==========#&amp;nbsp;1.&amp;nbsp;String类型（缓存用户信息，过期时间5分钟）user&amp;nbsp;=&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;id&amp;#39;:&amp;nbsp;1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;张三&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;create_time&amp;#39;:&amp;nbsp;datetime.now().strftime(&amp;#39;%Y-%m-%d&amp;nbsp;%H:%M:%S&amp;#39;)}#&amp;nbsp;序列化：推荐JSON（避免pickle序列化的安全风险）r.set(&amp;#39;user:1&amp;#39;,&amp;nbsp;json.dumps(user),&amp;nbsp;ex=300)&amp;nbsp;&amp;nbsp;#&amp;nbsp;ex=300&amp;nbsp;表示过期时间300秒#&amp;nbsp;读取String数据user_data&amp;nbsp;=&amp;nbsp;json.loads(r.get(&amp;#39;user:1&amp;#39;))print(&amp;quot;String类型读取：&amp;quot;,&amp;nbsp;user_data)#&amp;nbsp;2.&amp;nbsp;Hash类型（存储用户多字段信息）r.hset(&amp;#39;user:info&amp;#39;,&amp;nbsp;mapping={&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;李四&amp;#39;,&amp;nbsp;&amp;#39;age&amp;#39;:&amp;nbsp;25})#&amp;nbsp;读取Hash所有字段user_info&amp;nbsp;=&amp;nbsp;r.hgetall(&amp;#39;user:info&amp;#39;)print(&amp;quot;Hash类型读取：&amp;quot;,&amp;nbsp;user_info)#&amp;nbsp;3.&amp;nbsp;List类型（简易消息队列）r.lpush(&amp;#39;msg:queue&amp;#39;,&amp;nbsp;&amp;#39;订单创建通知&amp;#39;,&amp;nbsp;&amp;#39;支付成功通知&amp;#39;)#&amp;nbsp;弹出最后一个元素msg&amp;nbsp;=&amp;nbsp;r.rpop(&amp;#39;msg:queue&amp;#39;)print(&amp;quot;List类型读取：&amp;quot;,&amp;nbsp;msg)#&amp;nbsp;4.&amp;nbsp;批量操作（减少网络往返，提升性能）r.mset({&amp;#39;key1&amp;#39;:&amp;nbsp;&amp;#39;val1&amp;#39;,&amp;nbsp;&amp;#39;key2&amp;#39;:&amp;nbsp;&amp;#39;val2&amp;#39;,&amp;nbsp;&amp;#39;key3&amp;#39;:&amp;nbsp;&amp;#39;val3&amp;#39;})values&amp;nbsp;=&amp;nbsp;r.mget([&amp;#39;key1&amp;#39;,&amp;nbsp;&amp;#39;key2&amp;#39;,&amp;nbsp;&amp;#39;key3&amp;#39;])print(&amp;quot;批量读取：&amp;quot;,&amp;nbsp;values)&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 连接池优化（核心！避免频繁创建连接）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redis-py&lt;/code&gt;默认会为每个连接创建新的 TCP 连接，频繁操作时性能损耗大。通过连接池复用连接，是生产环境的必做优化：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7tlyqem&quot; data-popupid=&quot;7tlyqem&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0uwllr8&quot; data-popupid=&quot;0uwllr8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;n0w0tts&quot; data-popupid=&quot;n0w0tts&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5otzasu&quot; data-popupid=&quot;5otzasu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ji8xz18&quot; data-popupid=&quot;ji8xz18&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redisimport&amp;nbsp;json#&amp;nbsp;1.&amp;nbsp;初始化连接池（全局唯一，建议单例）redis_pool&amp;nbsp;=&amp;nbsp;redis.ConnectionPool(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host=&amp;#39;127.0.0.1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port=6379,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;db=0,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_timeout=3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;连接池核心参数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_connections=20,&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大连接数（根据并发量调整，建议10-50）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;retry_on_timeout=True,&amp;nbsp;&amp;nbsp;#&amp;nbsp;超时后重试
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;health_check_interval=30&amp;nbsp;&amp;nbsp;#&amp;nbsp;30秒检查一次连接健康状态)#&amp;nbsp;2.&amp;nbsp;从连接池获取连接（复用连接，无需重复创建）def&amp;nbsp;get_redis_client():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;redis.Redis(connection_pool=redis_pool)#&amp;nbsp;3.&amp;nbsp;使用示例r&amp;nbsp;=&amp;nbsp;get_redis_client()r.set(&amp;#39;test:pool&amp;#39;,&amp;nbsp;&amp;#39;连接池测试成功&amp;#39;)print(r.get(&amp;#39;test:pool&amp;#39;))&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. Django/Flask 框架集成&lt;/h3&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;Flask 集成 Redis（配置 + 工具类）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;oov2xcp&quot; data-popupid=&quot;oov2xcp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4ovb4yk&quot; data-popupid=&quot;4ovb4yk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1z8di2p&quot; data-popupid=&quot;1z8di2p&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;06qquy6&quot; data-popupid=&quot;06qquy6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qdq6v37&quot; data-popupid=&quot;qdq6v37&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#&amp;nbsp;app.pyfrom&amp;nbsp;flask&amp;nbsp;import&amp;nbsp;Flaskimport&amp;nbsp;redisimport&amp;nbsp;json

app&amp;nbsp;=&amp;nbsp;Flask(__name__)#&amp;nbsp;配置Redis连接池redis_pool&amp;nbsp;=&amp;nbsp;redis.ConnectionPool(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host=&amp;#39;127.0.0.1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port=6379,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_connections=15)#&amp;nbsp;封装Redis工具类class&amp;nbsp;RedisHelper:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@staticmethod
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;def&amp;nbsp;get_client():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;redis.Redis(connection_pool=redis_pool)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@staticmethod
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;def&amp;nbsp;set_cache(key,&amp;nbsp;value,&amp;nbsp;ex=None):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;quot;&amp;quot;设置缓存，自动序列化JSON&amp;quot;&amp;quot;&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client&amp;nbsp;=&amp;nbsp;RedisHelper.get_client()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client.set(key,&amp;nbsp;json.dumps(value),&amp;nbsp;ex=ex)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@staticmethod
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;def&amp;nbsp;get_cache(key):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;quot;&amp;quot;获取缓存，自动反序列化&amp;quot;&amp;quot;&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client&amp;nbsp;=&amp;nbsp;RedisHelper.get_client()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;client.get(key)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;json.loads(data)&amp;nbsp;if&amp;nbsp;data&amp;nbsp;else&amp;nbsp;None#&amp;nbsp;使用示例@app.route(&amp;#39;/set&amp;#39;)def&amp;nbsp;set_cache():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RedisHelper.set_cache(&amp;#39;flask:user:1&amp;#39;,&amp;nbsp;{&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;张三&amp;#39;,&amp;nbsp;&amp;#39;age&amp;#39;:&amp;nbsp;20},&amp;nbsp;ex=300)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;缓存设置成功&amp;quot;@app.route(&amp;#39;/get&amp;#39;)def&amp;nbsp;get_cache():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;RedisHelper.get_cache(&amp;#39;flask:user:1&amp;#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;f&amp;quot;缓存数据：{data}&amp;quot;if&amp;nbsp;__name__&amp;nbsp;==&amp;nbsp;&amp;#39;__main__&amp;#39;:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;app.run(debug=True)&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h4 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;Django 集成 Redis（settings 配置 + 自定义工具）&lt;/h4&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;28cwiym&quot; data-popupid=&quot;28cwiym&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;o3czqj2&quot; data-popupid=&quot;o3czqj2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ykhyj5p&quot; data-popupid=&quot;ykhyj5p&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;d8urlnr&quot; data-popupid=&quot;d8urlnr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3hjsnyd&quot; data-popupid=&quot;3hjsnyd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;#&amp;nbsp;settings.pyREDIS_CONFIG&amp;nbsp;=&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;host&amp;#39;:&amp;nbsp;&amp;#39;127.0.0.1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;port&amp;#39;:&amp;nbsp;6379,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;password&amp;#39;:&amp;nbsp;&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;db&amp;#39;:&amp;nbsp;0,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;decode_responses&amp;#39;:&amp;nbsp;True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;max_connections&amp;#39;:&amp;nbsp;20}#&amp;nbsp;utils/redis_utils.pyimport&amp;nbsp;redisimport&amp;nbsp;jsonfrom&amp;nbsp;django.conf&amp;nbsp;import&amp;nbsp;settings#&amp;nbsp;初始化连接池redis_pool&amp;nbsp;=&amp;nbsp;redis.ConnectionPool(**settings.REDIS_CONFIG)def&amp;nbsp;redis_client():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;redis.Redis(connection_pool=redis_pool)def&amp;nbsp;set_redis(key,&amp;nbsp;value,&amp;nbsp;ex=None):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client&amp;nbsp;=&amp;nbsp;redis_client()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client.set(key,&amp;nbsp;json.dumps(value),&amp;nbsp;ex=ex)def&amp;nbsp;get_redis(key):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client&amp;nbsp;=&amp;nbsp;redis_client()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;client.get(key)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;json.loads(data)&amp;nbsp;if&amp;nbsp;data&amp;nbsp;else&amp;nbsp;None#&amp;nbsp;视图中使用#&amp;nbsp;views.pyfrom&amp;nbsp;django.http&amp;nbsp;import&amp;nbsp;JsonResponsefrom&amp;nbsp;utils.redis_utils&amp;nbsp;import&amp;nbsp;set_redis,&amp;nbsp;get_redisdef&amp;nbsp;set_cache(request):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set_redis(&amp;#39;django:user:1&amp;#39;,&amp;nbsp;{&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;李四&amp;#39;,&amp;nbsp;&amp;#39;age&amp;#39;:&amp;nbsp;25},&amp;nbsp;ex=300)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;JsonResponse({&amp;#39;code&amp;#39;:&amp;nbsp;200,&amp;nbsp;&amp;#39;msg&amp;#39;:&amp;nbsp;&amp;#39;缓存设置成功&amp;#39;})def&amp;nbsp;get_cache(request):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;get_redis(&amp;#39;django:user:1&amp;#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;JsonResponse({&amp;#39;code&amp;#39;:&amp;nbsp;200,&amp;nbsp;&amp;#39;data&amp;#39;:&amp;nbsp;data})&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、进阶配置：Redis 集群与哨兵模式&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;生产环境中，单机 Redis 存在单点故障风险，需部署集群（分片扩容）或哨兵模式（高可用）保障稳定性。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 哨兵模式配置（高可用，解决单点故障）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;哨兵模式通过监控主从节点实现自动故障切换，适合数据量不大但需高可用的场景：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;yph6y9m&quot; data-popupid=&quot;yph6y9m&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bkyosig&quot; data-popupid=&quot;bkyosig&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;wy2qp6g&quot; data-popupid=&quot;wy2qp6g&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;89comsm&quot; data-popupid=&quot;89comsm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;85dk5d6&quot; data-popupid=&quot;85dk5d6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redisfrom&amp;nbsp;redis.sentinel&amp;nbsp;import&amp;nbsp;Sentinel#&amp;nbsp;1.&amp;nbsp;初始化哨兵客户端sentinel&amp;nbsp;=&amp;nbsp;Sentinel(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[(&amp;#39;192.168.1.100&amp;#39;,&amp;nbsp;26379),&amp;nbsp;(&amp;#39;192.168.1.101&amp;#39;,&amp;nbsp;26379),&amp;nbsp;(&amp;#39;192.168.1.102&amp;#39;,&amp;nbsp;26379)],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_timeout=3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True)#&amp;nbsp;2.&amp;nbsp;获取主节点（写入操作）master&amp;nbsp;=&amp;nbsp;sentinel.master_for(&amp;#39;mymaster&amp;#39;,&amp;nbsp;db=0)&amp;nbsp;&amp;nbsp;#&amp;nbsp;mymaster为哨兵配置的主节点名称master.set(&amp;#39;test:sentinel&amp;#39;,&amp;nbsp;&amp;#39;哨兵模式写入成功&amp;#39;)#&amp;nbsp;3.&amp;nbsp;获取从节点（读取操作，分流主节点压力）slave&amp;nbsp;=&amp;nbsp;sentinel.slave_for(&amp;#39;mymaster&amp;#39;,&amp;nbsp;db=0)print(&amp;quot;从节点读取：&amp;quot;,&amp;nbsp;slave.get(&amp;#39;test:sentinel&amp;#39;))&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 分片集群配置（水平扩容，支持海量数据）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;分片集群将数据分散到多个节点，适合数据量超过单机容量的场景（如电商商品缓存）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kdto4st&quot; data-popupid=&quot;kdto4st&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;lyrkmfw&quot; data-popupid=&quot;lyrkmfw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gmsn955&quot; data-popupid=&quot;gmsn955&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;igj5gws&quot; data-popupid=&quot;igj5gws&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;v50gfbf&quot; data-popupid=&quot;v50gfbf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redis.cluster#&amp;nbsp;初始化集群连接cluster&amp;nbsp;=&amp;nbsp;redis.cluster.RedisCluster(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;startup_nodes=[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;#39;host&amp;#39;:&amp;nbsp;&amp;#39;192.168.1.100&amp;#39;,&amp;nbsp;&amp;#39;port&amp;#39;:&amp;nbsp;6379},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;#39;host&amp;#39;:&amp;nbsp;&amp;#39;192.168.1.101&amp;#39;,&amp;nbsp;&amp;#39;port&amp;#39;:&amp;nbsp;6379},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;#39;host&amp;#39;:&amp;nbsp;&amp;#39;192.168.1.102&amp;#39;,&amp;nbsp;&amp;#39;port&amp;#39;:&amp;nbsp;6379}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_timeout=3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;集群参数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_redirects=3,&amp;nbsp;&amp;nbsp;#&amp;nbsp;最大重定向次数（默认3）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skip_full_coverage_check=True&amp;nbsp;&amp;nbsp;#&amp;nbsp;跳过集群全覆盖检查（开发/测试场景）)#&amp;nbsp;集群操作（与单机语法一致）cluster.set(&amp;#39;product:1001&amp;#39;,&amp;nbsp;json.dumps({&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;小米手机&amp;#39;,&amp;nbsp;&amp;#39;price&amp;#39;:&amp;nbsp;1999}))product&amp;nbsp;=&amp;nbsp;json.loads(cluster.get(&amp;#39;product:1001&amp;#39;))print(&amp;quot;集群读取：&amp;quot;,&amp;nbsp;product)&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、生产级优化技巧&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 管道（Pipeline）提升批量操作性能&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;管道可以将多个命令打包发送，减少网络往返次数（相比单次操作性能提升 5-10 倍）：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;u0cfy1w&quot; data-popupid=&quot;u0cfy1w&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;twlv6wc&quot; data-popupid=&quot;twlv6wc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jccj4mm&quot; data-popupid=&quot;jccj4mm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0ec3ihe&quot; data-popupid=&quot;0ec3ihe&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r84ci6x&quot; data-popupid=&quot;r84ci6x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redis#&amp;nbsp;初始化连接池（复用之前的配置）r&amp;nbsp;=&amp;nbsp;get_redis_client()#&amp;nbsp;创建管道pipe&amp;nbsp;=&amp;nbsp;r.pipeline(transaction=False)&amp;nbsp;&amp;nbsp;#&amp;nbsp;transaction=False&amp;nbsp;关闭事务，提升性能#&amp;nbsp;批量添加命令pipe.set(&amp;#39;pipe:1&amp;#39;,&amp;nbsp;&amp;#39;val1&amp;#39;)pipe.hset(&amp;#39;pipe:hash&amp;#39;,&amp;nbsp;mapping={&amp;#39;a&amp;#39;:&amp;nbsp;1,&amp;nbsp;&amp;#39;b&amp;#39;:&amp;nbsp;2})pipe.lpush(&amp;#39;pipe:list&amp;#39;,&amp;nbsp;&amp;#39;item1&amp;#39;,&amp;nbsp;&amp;#39;item2&amp;#39;)#&amp;nbsp;执行所有命令pipe.execute()#&amp;nbsp;读取结果print(r.get(&amp;#39;pipe:1&amp;#39;))print(r.hgetall(&amp;#39;pipe:hash&amp;#39;))&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 异步客户端（适配高并发异步场景）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;若使用 FastAPI/Starlette 等异步框架，推荐使用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgba(0, 0, 0, 0.85); margin: 0px; padding: 0px 4px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; overflow-anchor: auto; line-height: 28px; color: rgba(0, 0, 0, 0.85) !important;&quot;&gt;redis.asyncio&lt;/code&gt;异步客户端，避免阻塞事件循环：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1fm6wds&quot; data-popupid=&quot;1fm6wds&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;houe1ym&quot; data-popupid=&quot;houe1ym&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2lhr5sh&quot; data-popupid=&quot;2lhr5sh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0l4fit1&quot; data-popupid=&quot;0l4fit1&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vxeobrr&quot; data-popupid=&quot;vxeobrr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;asyncioimport&amp;nbsp;redis.asyncio&amp;nbsp;as&amp;nbsp;redis&amp;nbsp;&amp;nbsp;#&amp;nbsp;异步客户端import&amp;nbsp;jsonasync&amp;nbsp;def&amp;nbsp;async_redis_demo():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;异步连接池
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pool&amp;nbsp;=&amp;nbsp;redis.ConnectionPool.from_url(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;#39;redis://:123456@127.0.0.1:6379/0&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;max_connections=20
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;异步客户端
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;=&amp;nbsp;redis.Redis(connection_pool=pool)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;异步操作
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;await&amp;nbsp;r.set(&amp;#39;async:test&amp;#39;,&amp;nbsp;json.dumps({&amp;#39;name&amp;#39;:&amp;nbsp;&amp;#39;异步测试&amp;#39;}),&amp;nbsp;ex=300)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;await&amp;nbsp;r.get(&amp;#39;async:test&amp;#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(&amp;quot;异步读取：&amp;quot;,&amp;nbsp;json.loads(data))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#&amp;nbsp;关闭连接池
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;await&amp;nbsp;pool.disconnect()#&amp;nbsp;运行异步函数asyncio.run(async_redis_demo())&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 异常处理与自动重连&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;生产环境需捕获 Redis 异常，实现自动重连机制，避免服务中断：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8wn9vw4&quot; data-popupid=&quot;8wn9vw4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qz2ik12&quot; data-popupid=&quot;qz2ik12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3rangpv&quot; data-popupid=&quot;3rangpv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8rd730k&quot; data-popupid=&quot;8rd730k&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;90qabs9&quot; data-popupid=&quot;90qabs9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;import&amp;nbsp;redisimport&amp;nbsp;jsonimport&amp;nbsp;timedef&amp;nbsp;get_redis_client():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;&amp;quot;&amp;quot;带重连机制的Redis客户端&amp;quot;&amp;quot;&amp;quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;retry_count&amp;nbsp;=&amp;nbsp;3&amp;nbsp;&amp;nbsp;#&amp;nbsp;重试次数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while&amp;nbsp;retry_count&amp;nbsp;&amp;gt;&amp;nbsp;0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;redis.Redis(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host=&amp;#39;127.0.0.1&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;port=6379,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password=&amp;#39;123456&amp;#39;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decode_responses=True,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;socket_timeout=3,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;retry_on_timeout=True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;except&amp;nbsp;redis.RedisError&amp;nbsp;as&amp;nbsp;e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;retry_count&amp;nbsp;-=&amp;nbsp;1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(f&amp;quot;Redis连接失败，剩余重试次数：{retry_count}，错误：{e}&amp;quot;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;time.sleep(1)&amp;nbsp;&amp;nbsp;#&amp;nbsp;等待1秒后重试
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;raise&amp;nbsp;Exception(&amp;quot;Redis服务连接失败，已达最大重试次数&amp;quot;)#&amp;nbsp;使用示例try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&amp;nbsp;=&amp;nbsp;get_redis_client()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r.set(&amp;#39;test:retry&amp;#39;,&amp;nbsp;&amp;#39;重连机制测试成功&amp;#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(r.get(&amp;#39;test:retry&amp;#39;))except&amp;nbsp;Exception&amp;nbsp;as&amp;nbsp;e:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(f&amp;quot;最终失败：{e}&amp;quot;)&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;4. 序列化优化（避免 pickle 安全风险）&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;禁止使用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;pickle&lt;/code&gt;序列化：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;pickle&lt;/code&gt;存在反序列化漏洞，生产环境严禁使用；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;优先使用 JSON：复杂对象先转为 JSON 字符串，注意处理日期类型：&lt;/p&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--python hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 773.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gagncdl&quot; data-popupid=&quot;gagncdl&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;python&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gfkqs71&quot; data-popupid=&quot;gfkqs71&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hlmwzjh&quot; data-popupid=&quot;hlmwzjh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;mfinjpa&quot; data-popupid=&quot;mfinjpa&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;tzsdk0z&quot; data-popupid=&quot;tzsdk0z&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-python&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;from&amp;nbsp;datetime&amp;nbsp;import&amp;nbsp;datetime,&amp;nbsp;date#&amp;nbsp;自定义JSON编码器（处理日期类型）class&amp;nbsp;JSONEncoder(json.JSONEncoder):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;def&amp;nbsp;default(self,&amp;nbsp;obj):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;isinstance(obj,&amp;nbsp;(datetime,&amp;nbsp;date)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;obj.isoformat()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;super().default(obj)#&amp;nbsp;序列化data&amp;nbsp;=&amp;nbsp;{&amp;#39;time&amp;#39;:&amp;nbsp;datetime.now(),&amp;nbsp;&amp;#39;date&amp;#39;:&amp;nbsp;date.today()}r.set(&amp;#39;test:json&amp;#39;,&amp;nbsp;json.dumps(data,&amp;nbsp;cls=JSONEncoder))#&amp;nbsp;反序列化res&amp;nbsp;=&amp;nbsp;json.loads(r.get(&amp;#39;test:json&amp;#39;))#&amp;nbsp;还原日期类型（可选）res[&amp;#39;time&amp;#39;]&amp;nbsp;=&amp;nbsp;datetime.fromisoformat(res[&amp;#39;time&amp;#39;])print(res)&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、常见问题排查&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 连接超时 / 拒绝连接&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;检查 Redis 服务状态：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;systemctl status redis&lt;/code&gt;；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查 Redis 配置：&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;bind 0.0.0.0&lt;/code&gt;（允许外部访问）、&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;protected-mode no&lt;/code&gt;（关闭保护模式）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查防火墙：开放 6379 端口（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;firewall-cmd --add-port=6379/tcp --permanent &amp;amp;&amp;amp; firewall-cmd --reload&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 集群操作报 MOVED 错误&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;确保使用&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;redis.cluster.RedisCluster&lt;/code&gt;而非&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;redis.Redis&lt;/code&gt;；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查集群节点是否全部配置，且集群状态正常（&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;redis-cli --cluster check 192.168.1.100:6379&lt;/code&gt;）。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 连接池耗尽（Too many connections）&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;调大&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;max_connections&lt;/code&gt;参数（根据并发量调整）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;检查代码是否存在连接未释放（如未使用连接池、频繁创建客户端）；&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;配合 Redis 服务端&lt;code style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px none rgb(0, 0, 0); margin: 0px; padding: 0px 3.6px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-feature-settings: normal; font-size: 14.4px; font-variation-settings: normal; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 3.6px; overflow-anchor: auto;&quot;&gt;maxclients&lt;/code&gt;参数（默认 10000），避免超过上限。&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、总结&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文覆盖了 Python 整合 Redis 的全场景：基础连接满足开发需求，连接池 + 管道提升性能，哨兵 / 集群保障生产高可用，异步客户端适配现代异步框架。实际开发中，需根据业务规模选择方案 —— 小项目用单机 + 连接池，中大型项目用哨兵 / 集群，同时规避序列化安全风险、做好异常处理，才能让 Redis 真正发挥高性能优势。&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 02 Dec 2025 17:49:54 +0800</pubDate></item><item><title>Unity 开发实战：实现完整的物品购买系统</title><link>https://songhongblog.top/?id=28</link><description>&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在大多数游戏中，物品购买系统是连接玩家与游戏经济体系的核心环节，无论是商店购物、道具购买还是内购系统，都需要一个稳定可靠的购买逻辑。本文将详细介绍如何在 Unity 中构建一套完整的物品购买系统，包括货币管理、商品配置、购买流程、交易记录和安全验证等核心功能。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、购买系统核心需求分析&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一个完善的物品购买系统应包含以下核心要素：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;多类型货币支持（金币、钻石、代币等）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;商品信息管理（价格、折扣、限购等）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;购买流程控制（验证、扣款、发奖）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;交易记录与日志&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;购买冷却与限购机制&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;错误处理与提示（余额不足、购买失败等）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;商店 UI 展示（商品列表、详情、购买按钮）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;内购集成（可选，对接支付 SDK）&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、数据结构设计&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;采用 ScriptableObject 存储商品配置数据，使用运行时数据类管理购买状态和货币信息，实现数据与逻辑分离。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 基础定义&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;om86l5g&quot; data-popupid=&quot;om86l5g&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;evbjxls&quot; data-popupid=&quot;evbjxls&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9qtsj5f&quot; data-popupid=&quot;9qtsj5f&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ooodehc&quot; data-popupid=&quot;ooodehc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;oodgpzt&quot; data-popupid=&quot;oodgpzt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;货币类型public&amp;nbsp;enum&amp;nbsp;CurrencyType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Gold,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;金币（游戏内货币）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Diamond,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;钻石（&amp;nbsp;premium&amp;nbsp;货币）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Token,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;代币（活动货币）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RealMoney&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;真实货币（内购）}//&amp;nbsp;商品类型public&amp;nbsp;enum&amp;nbsp;ProductType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Consumable,&amp;nbsp;//&amp;nbsp;消耗品（如药水）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Equipment,&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Skin,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;皮肤
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Bundle,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;礼包
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Currency,&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;货币包
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Function&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;功能解锁}//&amp;nbsp;购买结果public&amp;nbsp;enum&amp;nbsp;PurchaseResult{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Success,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;成功
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InsufficientFunds,&amp;nbsp;&amp;nbsp;//&amp;nbsp;资金不足
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PurchaseFailed,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买失败
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OutOfStock,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;缺货
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LimitExceeded,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;超过限购
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NotUnlocked,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;未解锁
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InvalidProduct&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品无效}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 商品配置数据（ScriptableObject）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2lyragt&quot; data-popupid=&quot;2lyragt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;7d3dfjs&quot; data-popupid=&quot;7d3dfjs&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5jwb69l&quot; data-popupid=&quot;5jwb69l&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0xfn2c2&quot; data-popupid=&quot;0xfn2c2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;qh6be0a&quot; data-popupid=&quot;qh6be0a&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System.Collections.Generic;[CreateAssetMenu(fileName&amp;nbsp;=&amp;nbsp;&amp;quot;ProductData&amp;quot;,&amp;nbsp;menuName&amp;nbsp;=&amp;nbsp;&amp;quot;Shop/ProductData&amp;quot;)]public&amp;nbsp;class&amp;nbsp;ProductData&amp;nbsp;:&amp;nbsp;ScriptableObject{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;基础信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;productId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品唯一ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;productName;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;description;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品描述
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Sprite&amp;nbsp;icon;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品图标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ProductType&amp;nbsp;productType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品类型

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;价格信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;CurrencyType&amp;nbsp;currencyType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;货币类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;basePrice;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;基础价格
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;discount&amp;nbsp;=&amp;nbsp;1f;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;折扣（1为无折扣）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isOnSale&amp;nbsp;=&amp;gt;&amp;nbsp;discount&amp;nbsp;&amp;lt;&amp;nbsp;1f;&amp;nbsp;//&amp;nbsp;是否在打折

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;库存与限购&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;stock;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;库存（-1为无限）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;dailyPurchaseLimit&amp;nbsp;=&amp;nbsp;-1;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;每日限购（-1为无限）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;totalPurchaseLimit&amp;nbsp;=&amp;nbsp;-1;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;总限购（-1为无限）

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;内容信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;ItemAmount&amp;gt;&amp;nbsp;items;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;包含的物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;currencyAmount;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;包含的货币数量（如果是货币包）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;CurrencyType&amp;nbsp;currencyPackageType;&amp;nbsp;//&amp;nbsp;货币包类型

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;其他设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;requiredLevel&amp;nbsp;=&amp;nbsp;1;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买所需等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;requiredUnlockedFeature;&amp;nbsp;//&amp;nbsp;所需解锁的功能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isAvailable&amp;nbsp;=&amp;nbsp;true;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否可购买
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;iapProductId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;内购商品ID（如果是真实货币购买）}//&amp;nbsp;物品数量结构体[System.Serializable]public&amp;nbsp;struct&amp;nbsp;ItemAmount{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;itemId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;物品ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;amount;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;数量}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 购买记录与状态数据&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8iyy5md&quot; data-popupid=&quot;8iyy5md&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;swqtmh0&quot; data-popupid=&quot;swqtmh0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;cyhxbe7&quot; data-popupid=&quot;cyhxbe7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;opusoe2&quot; data-popupid=&quot;opusoe2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bw30g0n&quot; data-popupid=&quot;bw30g0n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;System;using&amp;nbsp;System.Collections.Generic;//&amp;nbsp;购买记录[System.Serializable]public&amp;nbsp;class&amp;nbsp;PurchaseRecord{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;productId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;DateTime&amp;nbsp;purchaseTime;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买时间
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;amount;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;pricePaid;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际支付价格
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;CurrencyType&amp;nbsp;currencyType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;支付货币类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;transactionId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;交易ID}//&amp;nbsp;商品购买状态（用于限购等）[System.Serializable]public&amp;nbsp;class&amp;nbsp;ProductPurchaseState{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;productId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;totalPurchased;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;总购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Dictionary&amp;lt;DateTime,&amp;nbsp;int&amp;gt;&amp;nbsp;dailyPurchases&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;DateTime,&amp;nbsp;int&amp;gt;();&amp;nbsp;//&amp;nbsp;每日购买记录}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、核心逻辑实现&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 货币管理器&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;负责管理玩家的各种货币余额和变动：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gyuwpr8&quot; data-popupid=&quot;gyuwpr8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;r2ja09t&quot; data-popupid=&quot;r2ja09t&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5j5v43h&quot; data-popupid=&quot;5j5v43h&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e306t9y&quot; data-popupid=&quot;e306t9y&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;t16ggc4&quot; data-popupid=&quot;t16ggc4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System.Collections.Generic;public&amp;nbsp;class&amp;nbsp;CurrencyManager&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;CurrencyManager&amp;nbsp;Instance&amp;nbsp;{&amp;nbsp;get;&amp;nbsp;private&amp;nbsp;set;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Dictionary&amp;lt;CurrencyType,&amp;nbsp;int&amp;gt;&amp;nbsp;currencies&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;CurrencyType,&amp;nbsp;int&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;事件定义
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;delegate&amp;nbsp;void&amp;nbsp;CurrencyChangedDelegate(CurrencyType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;newAmount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;CurrencyChangedDelegate&amp;nbsp;OnCurrencyChanged;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Awake()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(Instance&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Instance&amp;nbsp;=&amp;nbsp;this;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DontDestroyOnLoad(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InitializeCurrencies();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化货币
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;InitializeCurrencies()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化所有货币类型为0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(CurrencyType&amp;nbsp;type&amp;nbsp;in&amp;nbsp;Enum.GetValues(typeof(CurrencyType)))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!currencies.ContainsKey(type))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currencies[type]&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;从存档加载货币数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LoadCurrencyData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取货币余额
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;GetCurrencyBalance(CurrencyType&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(currencies.TryGetValue(type,&amp;nbsp;out&amp;nbsp;int&amp;nbsp;amount))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;amount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否有足够的货币
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;HasEnoughCurrency(CurrencyType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;GetCurrencyBalance(type)&amp;nbsp;&amp;gt;=&amp;nbsp;amount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;增加货币
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;AddCurrency(CurrencyType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(amount&amp;nbsp;&amp;lt;=&amp;nbsp;0)&amp;nbsp;return;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currencies[type]&amp;nbsp;+=&amp;nbsp;amount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnCurrencyChanged?.Invoke(type,&amp;nbsp;currencies[type]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SaveCurrencyData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;减少货币
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;SubtractCurrency(CurrencyType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(amount&amp;nbsp;&amp;lt;=&amp;nbsp;0)&amp;nbsp;return&amp;nbsp;true;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(HasEnoughCurrency(type,&amp;nbsp;amount))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currencies[type]&amp;nbsp;-=&amp;nbsp;amount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnCurrencyChanged?.Invoke(type,&amp;nbsp;currencies[type]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SaveCurrencyData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;保存货币数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;SaveCurrencyData()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应保存到持久化系统
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;currency&amp;nbsp;in&amp;nbsp;currencies)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PlayerPrefs.SetInt($&amp;quot;Currency_{currency.Key}&amp;quot;,&amp;nbsp;currency.Value);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PlayerPrefs.Save();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;加载货币数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;LoadCurrencyData()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(CurrencyType&amp;nbsp;type&amp;nbsp;in&amp;nbsp;Enum.GetValues(typeof(CurrencyType)))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(PlayerPrefs.HasKey($&amp;quot;Currency_{type}&amp;quot;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currencies[type]&amp;nbsp;=&amp;nbsp;PlayerPrefs.GetInt($&amp;quot;Currency_{type}&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnCurrencyChanged?.Invoke(type,&amp;nbsp;currencies[type]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 商店管理器（核心购买逻辑）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;v3guk2v&quot; data-popupid=&quot;v3guk2v&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;yhu2duc&quot; data-popupid=&quot;yhu2duc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4tmkhu5&quot; data-popupid=&quot;4tmkhu5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dvtoo4i&quot; data-popupid=&quot;dvtoo4i&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;j9wu8yj&quot; data-popupid=&quot;j9wu8yj&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System;using&amp;nbsp;System.Collections.Generic;using&amp;nbsp;System.Linq;public&amp;nbsp;class&amp;nbsp;ShopManager&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;ShopManager&amp;nbsp;Instance&amp;nbsp;{&amp;nbsp;get;&amp;nbsp;private&amp;nbsp;set;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;List&amp;lt;ProductData&amp;gt;&amp;nbsp;allProducts;&amp;nbsp;//&amp;nbsp;所有商品配置

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Dictionary&amp;lt;string,&amp;nbsp;ProductData&amp;gt;&amp;nbsp;products&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;string,&amp;nbsp;ProductData&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Dictionary&amp;lt;string,&amp;nbsp;ProductPurchaseState&amp;gt;&amp;nbsp;purchaseStates&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;string,&amp;nbsp;ProductPurchaseState&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;PurchaseRecord&amp;gt;&amp;nbsp;purchaseHistory&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;PurchaseRecord&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;事件定义
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;delegate&amp;nbsp;void&amp;nbsp;PurchaseCompletedDelegate(PurchaseResult&amp;nbsp;result,&amp;nbsp;ProductData&amp;nbsp;product,&amp;nbsp;PurchaseRecord&amp;nbsp;record);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;PurchaseCompletedDelegate&amp;nbsp;OnPurchaseCompleted;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;Action&amp;nbsp;OnShopDataUpdated;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Awake()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(Instance&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Instance&amp;nbsp;=&amp;nbsp;this;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DontDestroyOnLoad(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InitializeShop();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化商店
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;InitializeShop()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;构建商品字典
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;product&amp;nbsp;in&amp;nbsp;allProducts)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!products.ContainsKey(product.productId))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;products[product.productId]&amp;nbsp;=&amp;nbsp;product;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;加载购买状态和历史记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LoadPurchaseData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取所有商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;ProductData&amp;gt;&amp;nbsp;GetAllProducts()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;new&amp;nbsp;List&amp;lt;ProductData&amp;gt;(products.Values);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;按类型获取商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;ProductData&amp;gt;&amp;nbsp;GetProductsByType(ProductType&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;products.Values.Where(p&amp;nbsp;=&amp;gt;&amp;nbsp;p.productType&amp;nbsp;==&amp;nbsp;type&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;p.isAvailable).ToList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取商品详情
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ProductData&amp;nbsp;GetProductById(string&amp;nbsp;productId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(products.TryGetValue(productId,&amp;nbsp;out&amp;nbsp;ProductData&amp;nbsp;product))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;product;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算商品实际价格（考虑折扣）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;CalculateActualPrice(ProductData&amp;nbsp;product)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;Mathf.RoundToInt(product.basePrice&amp;nbsp;*&amp;nbsp;product.discount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查商品是否可购买
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;PurchaseResult&amp;nbsp;CanPurchaseProduct(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity&amp;nbsp;=&amp;nbsp;1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查商品是否有效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product&amp;nbsp;==&amp;nbsp;null&amp;nbsp;||&amp;nbsp;!product.isAvailable)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.InvalidProduct;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查等级限制
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(PlayerLevel.Instance.Level&amp;nbsp;&amp;lt;&amp;nbsp;product.requiredLevel)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.NotUnlocked;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查库存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.stock&amp;nbsp;!=&amp;nbsp;-1&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;product.stock&amp;nbsp;&amp;lt;&amp;nbsp;quantity)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.OutOfStock;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查限购
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;state&amp;nbsp;=&amp;nbsp;GetOrCreatePurchaseState(product.productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查总限购
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.totalPurchaseLimit&amp;nbsp;!=&amp;nbsp;-1&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state.totalPurchased&amp;nbsp;+&amp;nbsp;quantity&amp;nbsp;&amp;gt;&amp;nbsp;product.totalPurchaseLimit)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.LimitExceeded;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查每日限购
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.dailyPurchaseLimit&amp;nbsp;!=&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DateTime&amp;nbsp;today&amp;nbsp;=&amp;nbsp;DateTime.Today;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;todayPurchased&amp;nbsp;=&amp;nbsp;state.dailyPurchases.TryGetValue(today,&amp;nbsp;out&amp;nbsp;int&amp;nbsp;count)&amp;nbsp;?&amp;nbsp;count&amp;nbsp;:&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(todayPurchased&amp;nbsp;+&amp;nbsp;quantity&amp;nbsp;&amp;gt;&amp;nbsp;product.dailyPurchaseLimit)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.LimitExceeded;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查货币是否足够
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;actualPrice&amp;nbsp;=&amp;nbsp;CalculateActualPrice(product)&amp;nbsp;*&amp;nbsp;quantity;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!CurrencyManager.Instance.HasEnoughCurrency(product.currencyType,&amp;nbsp;actualPrice))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.InsufficientFunds;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;PurchaseResult.Success;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;PurchaseProduct(string&amp;nbsp;productId,&amp;nbsp;int&amp;nbsp;quantity&amp;nbsp;=&amp;nbsp;1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductData&amp;nbsp;product&amp;nbsp;=&amp;nbsp;GetProductById(productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.InvalidProduct,&amp;nbsp;null,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;先检查是否可购买
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PurchaseResult&amp;nbsp;preCheck&amp;nbsp;=&amp;nbsp;CanPurchaseProduct(product,&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(preCheck&amp;nbsp;!=&amp;nbsp;PurchaseResult.Success)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(preCheck,&amp;nbsp;product,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算实际价格
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;actualPrice&amp;nbsp;=&amp;nbsp;CalculateActualPrice(product)&amp;nbsp;*&amp;nbsp;quantity;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;处理内购商品（真实货币购买）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.currencyType&amp;nbsp;==&amp;nbsp;CurrencyType.RealMoney)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;调用IAP服务
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartIAPurchase(product,&amp;nbsp;quantity,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;游戏内货币购买流程
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProcessInGamePurchase(product,&amp;nbsp;quantity,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;处理游戏内货币购买
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ProcessInGamePurchase(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity,&amp;nbsp;int&amp;nbsp;actualPrice)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;扣减货币
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;paymentSuccess&amp;nbsp;=&amp;nbsp;CurrencyManager.Instance.SubtractCurrency(product.currencyType,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!paymentSuccess)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.InsufficientFunds,&amp;nbsp;product,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;itemGrantSuccess&amp;nbsp;=&amp;nbsp;GrantProductItems(product,&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!itemGrantSuccess)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放失败，退款
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CurrencyManager.Instance.AddCurrency(product.currencyType,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.PurchaseFailed,&amp;nbsp;product,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新购买状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdatePurchaseState(product,&amp;nbsp;quantity);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建购买记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PurchaseRecord&amp;nbsp;record&amp;nbsp;=&amp;nbsp;CreatePurchaseRecord(product,&amp;nbsp;quantity,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseHistory.Add(record);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;保存数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SavePurchaseData();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发购买完成事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.Success,&amp;nbsp;product,&amp;nbsp;record);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;处理内购（示例）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;StartIAPurchase(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity,&amp;nbsp;int&amp;nbsp;actualPrice)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应调用IAP&amp;nbsp;SDK，如Unity&amp;nbsp;IAP
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;这里仅做示例
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#if&amp;nbsp;UNITY_IAP
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化IAP购买流程
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;IAPManager.Instance.PurchaseProduct(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;product.iapProductId,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onSuccess:&amp;nbsp;(transactionId)&amp;nbsp;=&amp;gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;内购成功，发放物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GrantProductItems(product,&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdatePurchaseState(product,&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PurchaseRecord&amp;nbsp;record&amp;nbsp;=&amp;nbsp;CreatePurchaseRecord(product,&amp;nbsp;quantity,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;record.transactionId&amp;nbsp;=&amp;nbsp;transactionId;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseHistory.Add(record);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SavePurchaseData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.Success,&amp;nbsp;product,&amp;nbsp;record);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onFailed:&amp;nbsp;()&amp;nbsp;=&amp;gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseCompleted?.Invoke(PurchaseResult.PurchaseFailed,&amp;nbsp;product,&amp;nbsp;null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;没有IAP支持时的模拟
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProcessInGamePurchase(product,&amp;nbsp;quantity,&amp;nbsp;actualPrice);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#endif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放商品包含的物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;bool&amp;nbsp;GrantProductItems(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;item&amp;nbsp;in&amp;nbsp;product.items)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InventoryManager.Instance.AddItem(item.itemId,&amp;nbsp;item.amount&amp;nbsp;*&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放货币（如果是货币包）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.productType&amp;nbsp;==&amp;nbsp;ProductType.Currency&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;product.currencyAmount&amp;nbsp;&amp;gt;&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CurrencyManager.Instance.AddCurrency(product.currencyPackageType,&amp;nbsp;product.currencyAmount&amp;nbsp;*&amp;nbsp;quantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;catch&amp;nbsp;(Exception&amp;nbsp;e)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.LogError($&amp;quot;发放物品失败:&amp;nbsp;{e.Message}&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新购买状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdatePurchaseState(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;state&amp;nbsp;=&amp;nbsp;GetOrCreatePurchaseState(product.productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新总购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state.totalPurchased&amp;nbsp;+=&amp;nbsp;quantity;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新每日购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DateTime&amp;nbsp;today&amp;nbsp;=&amp;nbsp;DateTime.Today;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(state.dailyPurchases.ContainsKey(today))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state.dailyPurchases[today]&amp;nbsp;+=&amp;nbsp;quantity;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state.dailyPurchases[today]&amp;nbsp;=&amp;nbsp;quantity;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新库存
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.stock&amp;nbsp;!=&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;注意：ScriptableObject是资产文件，不应在运行时修改
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应使用实例化的商品数据或单独的库存管理
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建购买记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;PurchaseRecord&amp;nbsp;CreatePurchaseRecord(ProductData&amp;nbsp;product,&amp;nbsp;int&amp;nbsp;quantity,&amp;nbsp;int&amp;nbsp;actualPrice)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;new&amp;nbsp;PurchaseRecord
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;productId&amp;nbsp;=&amp;nbsp;product.productId,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseTime&amp;nbsp;=&amp;nbsp;DateTime.Now,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;amount&amp;nbsp;=&amp;nbsp;quantity,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pricePaid&amp;nbsp;=&amp;nbsp;actualPrice,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currencyType&amp;nbsp;=&amp;nbsp;product.currencyType,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;transactionId&amp;nbsp;=&amp;nbsp;Guid.NewGuid().ToString()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取或创建购买状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ProductPurchaseState&amp;nbsp;GetOrCreatePurchaseState(string&amp;nbsp;productId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!purchaseStates.TryGetValue(productId,&amp;nbsp;out&amp;nbsp;ProductPurchaseState&amp;nbsp;state))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state&amp;nbsp;=&amp;nbsp;new&amp;nbsp;ProductPurchaseState&amp;nbsp;{&amp;nbsp;productId&amp;nbsp;=&amp;nbsp;productId&amp;nbsp;};
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseStates[productId]&amp;nbsp;=&amp;nbsp;state;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;state;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取商品购买状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ProductPurchaseState&amp;nbsp;GetPurchaseState(string&amp;nbsp;productId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseStates.TryGetValue(productId,&amp;nbsp;out&amp;nbsp;ProductPurchaseState&amp;nbsp;state);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;state;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取购买历史
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;PurchaseRecord&amp;gt;&amp;nbsp;GetPurchaseHistory()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;new&amp;nbsp;List&amp;lt;PurchaseRecord&amp;gt;(purchaseHistory);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;保存购买数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;SavePurchaseData()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应使用更高效的序列化方式
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;这里仅做示例
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SaveSystem.Instance.SavePurchaseStates(purchaseStates);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SaveSystem.Instance.SavePurchaseHistory(purchaseHistory);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;加载购买数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;LoadPurchaseData()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseStates&amp;nbsp;=&amp;nbsp;SaveSystem.Instance.LoadPurchaseStates();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseHistory&amp;nbsp;=&amp;nbsp;SaveSystem.Instance.LoadPurchaseHistory();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新商店数据（如每日限购重置）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;RefreshShop()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;清理过期的每日购买记录
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;state&amp;nbsp;in&amp;nbsp;purchaseStates.Values)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;DateTime&amp;gt;&amp;nbsp;expiredDates&amp;nbsp;=&amp;nbsp;state.dailyPurchases.Keys&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Where(date&amp;nbsp;=&amp;gt;&amp;nbsp;date&amp;nbsp;&amp;lt;&amp;nbsp;DateTime.Today)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.ToList();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;date&amp;nbsp;in&amp;nbsp;expiredDates)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;state.dailyPurchases.Remove(date);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SavePurchaseData();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnShopDataUpdated?.Invoke();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、UI 界面实现&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 商店 UI 管理器&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;44oqfwd&quot; data-popupid=&quot;44oqfwd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;w31rocr&quot; data-popupid=&quot;w31rocr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5z5nrun&quot; data-popupid=&quot;5z5nrun&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9hc0m73&quot; data-popupid=&quot;9hc0m73&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;u3azq0t&quot; data-popupid=&quot;u3azq0t&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;UnityEngine.UI;using&amp;nbsp;TMPro;using&amp;nbsp;System.Collections.Generic;public&amp;nbsp;class&amp;nbsp;ShopUI&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;商店容器&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Transform&amp;nbsp;productGrid;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;productCardPrefab;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;List&amp;lt;Button&amp;gt;&amp;nbsp;categoryButtons;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;商品详情&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;detailPanel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;detailIcon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;detailName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;detailDescription;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;detailPrice;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;detailOriginalPrice;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;stockInfo;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;limitInfo;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;purchaseButton;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;closeDetailButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;购买数量&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;increaseButton;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;decreaseButton;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;quantityText;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;提示信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;messagePanel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;messageText;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;ProductCard&amp;gt;&amp;nbsp;productCards&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;ProductCard&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ProductData&amp;nbsp;selectedProduct;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;int&amp;nbsp;currentQuantity&amp;nbsp;=&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ProductType&amp;nbsp;currentCategory&amp;nbsp;=&amp;nbsp;ProductType.Consumable;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Start()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;注册事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.OnPurchaseCompleted&amp;nbsp;+=&amp;nbsp;OnPurchaseCompleted;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.OnShopDataUpdated&amp;nbsp;+=&amp;nbsp;RefreshShopUI;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CurrencyManager.Instance.OnCurrencyChanged&amp;nbsp;+=&amp;nbsp;UpdateCurrencyDisplay;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;绑定按钮事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;purchaseButton.onClick.AddListener(OnPurchaseButtonClicked);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;closeDetailButton.onClick.AddListener(HideDetailPanel);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;increaseButton.onClick.AddListener(IncreaseQuantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decreaseButton.onClick.AddListener(DecreaseQuantity);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;绑定分类按钮事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;categoryButtons.Count&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;Enum.GetValues(typeof(ProductType)).Length;&amp;nbsp;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;index&amp;nbsp;=&amp;nbsp;i;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;categoryButtons[i].onClick.AddListener(()&amp;nbsp;=&amp;gt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCategory&amp;nbsp;=&amp;nbsp;(ProductType)index;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshProductList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化UI
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshShopUI();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HideDetailPanel();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HideMessagePanel();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新商店UI
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;RefreshShopUI()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshProductList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateCurrencyDisplay(CurrencyType.Gold,&amp;nbsp;CurrencyManager.Instance.GetCurrencyBalance(CurrencyType.Gold));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新商品列表
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;RefreshProductList()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;清除现有商品卡片
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;card&amp;nbsp;in&amp;nbsp;productCards)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(card.gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;productCards.Clear();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取对应分类的商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;ProductData&amp;gt;&amp;nbsp;products&amp;nbsp;=&amp;nbsp;ShopManager.Instance.GetProductsByType(currentCategory);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建商品卡片
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;product&amp;nbsp;in&amp;nbsp;products)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GameObject&amp;nbsp;cardObj&amp;nbsp;=&amp;nbsp;Instantiate(productCardPrefab,&amp;nbsp;productGrid);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductCard&amp;nbsp;card&amp;nbsp;=&amp;nbsp;cardObj.GetComponent&amp;lt;ProductCard&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;card.Initialize(product,&amp;nbsp;OnProductCardClicked);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;productCards.Add(card);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;商品卡片点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnProductCardClicked(ProductData&amp;nbsp;product)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;selectedProduct&amp;nbsp;=&amp;nbsp;product;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentQuantity&amp;nbsp;=&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowDetailPanel(product);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示商品详情
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ShowDetailPanel(ProductData&amp;nbsp;product)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailIcon.sprite&amp;nbsp;=&amp;nbsp;product.icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailName.text&amp;nbsp;=&amp;nbsp;product.productName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailDescription.text&amp;nbsp;=&amp;nbsp;product.description;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;价格显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;actualPrice&amp;nbsp;=&amp;nbsp;ShopManager.Instance.CalculateActualPrice(product);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPrice.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{actualPrice}&amp;nbsp;{product.currencyType}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;原价（折扣时显示）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.isOnSale)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailOriginalPrice.gameObject.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailOriginalPrice.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{product.basePrice}&amp;nbsp;{product.currencyType}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailOriginalPrice.gameObject.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;库存信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.stock&amp;nbsp;==&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stockInfo.text&amp;nbsp;=&amp;nbsp;&amp;quot;库存:&amp;nbsp;无限&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stockInfo.text&amp;nbsp;=&amp;nbsp;$&amp;quot;库存:&amp;nbsp;{product.stock}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;限购信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;state&amp;nbsp;=&amp;nbsp;ShopManager.Instance.GetPurchaseState(product.productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;limitText&amp;nbsp;=&amp;nbsp;&amp;quot;&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.totalPurchaseLimit&amp;nbsp;!=&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;remainingTotal&amp;nbsp;=&amp;nbsp;product.totalPurchaseLimit&amp;nbsp;-&amp;nbsp;(state?.totalPurchased&amp;nbsp;??&amp;nbsp;0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;limitText&amp;nbsp;+=&amp;nbsp;$&amp;quot;总限购:&amp;nbsp;剩余&amp;nbsp;{remainingTotal}/{product.totalPurchaseLimit}\n&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.dailyPurchaseLimit&amp;nbsp;!=&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;todayPurchased&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(state&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;state.dailyPurchases.TryGetValue(DateTime.Today,&amp;nbsp;out&amp;nbsp;int&amp;nbsp;count))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;todayPurchased&amp;nbsp;=&amp;nbsp;count;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;remainingDaily&amp;nbsp;=&amp;nbsp;product.dailyPurchaseLimit&amp;nbsp;-&amp;nbsp;todayPurchased;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;limitText&amp;nbsp;+=&amp;nbsp;$&amp;quot;每日限购:&amp;nbsp;剩余&amp;nbsp;{remainingDaily}/{product.dailyPurchaseLimit}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;limitInfo.text&amp;nbsp;=&amp;nbsp;limitText;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新数量显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateQuantityDisplay();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏详情面板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;HideDetailPanel()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;selectedProduct&amp;nbsp;=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;增加购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;IncreaseQuantity()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedProduct&amp;nbsp;==&amp;nbsp;null)&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否可以增加数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;newQuantity&amp;nbsp;=&amp;nbsp;currentQuantity&amp;nbsp;+&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PurchaseResult&amp;nbsp;result&amp;nbsp;=&amp;nbsp;ShopManager.Instance.CanPurchaseProduct(selectedProduct,&amp;nbsp;newQuantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(result&amp;nbsp;==&amp;nbsp;PurchaseResult.Success)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentQuantity&amp;nbsp;=&amp;nbsp;newQuantity;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateQuantityDisplay();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowMessage(GetResultMessage(result));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;减少购买数量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;DecreaseQuantity()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(currentQuantity&amp;nbsp;&amp;gt;&amp;nbsp;1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentQuantity--;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateQuantityDisplay();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新数量显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateQuantityDisplay()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;quantityText.text&amp;nbsp;=&amp;nbsp;currentQuantity.ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;decreaseButton.interactable&amp;nbsp;=&amp;nbsp;currentQuantity&amp;nbsp;&amp;gt;&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买按钮点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnPurchaseButtonClicked()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedProduct&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.PurchaseProduct(selectedProduct.productId,&amp;nbsp;currentQuantity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买完成回调
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnPurchaseCompleted(PurchaseResult&amp;nbsp;result,&amp;nbsp;ProductData&amp;nbsp;product,&amp;nbsp;PurchaseRecord&amp;nbsp;record)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(result&amp;nbsp;==&amp;nbsp;PurchaseResult.Success)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowMessage($&amp;quot;成功购买&amp;nbsp;{product.productName}&amp;nbsp;x{record.amount}!&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HideDetailPanel();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshShopUI();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowMessage(GetResultMessage(result));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示提示信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ShowMessage(string&amp;nbsp;message)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;messageText.text&amp;nbsp;=&amp;nbsp;message;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;messagePanel.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Invoke(nameof(HideMessagePanel),&amp;nbsp;3f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏提示信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;HideMessagePanel()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;messagePanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新货币显示（实际项目中应实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateCurrencyDisplay(CurrencyType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;newAmount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新UI上的货币显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取购买结果对应的消息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;string&amp;nbsp;GetResultMessage(PurchaseResult&amp;nbsp;result)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;nbsp;(result)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.InsufficientFunds:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;货币不足，无法购买&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.OutOfStock:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;商品已售罄&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.LimitExceeded:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;已超过限购数量&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.NotUnlocked:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;等级不足，无法购买&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.InvalidProduct:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;无效的商品&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;PurchaseResult.PurchaseFailed:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;购买失败，请重试&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;default:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;&amp;quot;未知错误&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}//&amp;nbsp;商品卡片UI组件public&amp;nbsp;class&amp;nbsp;ProductCard&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;nameText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;priceText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;originalPriceText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;saleTag;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;buyButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ProductData&amp;nbsp;product;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Action&amp;lt;ProductData&amp;gt;&amp;nbsp;onClickAction;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize(ProductData&amp;nbsp;productData,&amp;nbsp;Action&amp;lt;ProductData&amp;gt;&amp;nbsp;onClick)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;product&amp;nbsp;=&amp;nbsp;productData;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onClickAction&amp;nbsp;=&amp;nbsp;onClick;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置卡片信息
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.sprite&amp;nbsp;=&amp;nbsp;product.icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nameText.text&amp;nbsp;=&amp;nbsp;product.productName;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;价格显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;actualPrice&amp;nbsp;=&amp;nbsp;ShopManager.Instance.CalculateActualPrice(product);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;priceText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{actualPrice}&amp;nbsp;{product.currencyType}&amp;quot;;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;折扣显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product.isOnSale)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;saleTag.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;originalPriceText.gameObject.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;originalPriceText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{product.basePrice}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;saleTag.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;originalPriceText.gameObject.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;绑定点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buyButton.onClick.AddListener(OnClick);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnClick()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onClickAction?.Invoke(product);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、系统扩展与安全考虑&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 优惠活动系统&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;扩展商店系统支持限时优惠和活动：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;yt9ms79&quot; data-popupid=&quot;yt9ms79&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;l3ro2nz&quot; data-popupid=&quot;l3ro2nz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;b7g9fb2&quot; data-popupid=&quot;b7g9fb2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1416ikz&quot; data-popupid=&quot;1416ikz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vkxf7xu&quot; data-popupid=&quot;vkxf7xu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;ShopEventSystem&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;List&amp;lt;EventProduct&amp;gt;&amp;nbsp;eventProducts;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;float&amp;nbsp;eventDuration&amp;nbsp;=&amp;nbsp;86400f;&amp;nbsp;//&amp;nbsp;24小时

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;float&amp;nbsp;eventStartTime;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;bool&amp;nbsp;isEventActive&amp;nbsp;=&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Start()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;可以通过远程配置控制活动是否开启
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartEvent();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;开始活动
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;StartEvent()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eventStartTime&amp;nbsp;=&amp;nbsp;Time.time;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isEventActive&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AddEventProducts();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;结束活动
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;EndEvent()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isEventActive&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RemoveEventProducts();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;添加活动商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;AddEventProducts()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;eventProduct&amp;nbsp;in&amp;nbsp;eventProducts)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;克隆商品数据并应用活动折扣
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductData&amp;nbsp;eventData&amp;nbsp;=&amp;nbsp;Instantiate(eventProduct.originalProduct);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eventData.productId&amp;nbsp;=&amp;nbsp;$&amp;quot;{eventData.productId}_event&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eventData.discount&amp;nbsp;=&amp;nbsp;eventProduct.eventDiscount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;eventData.isAvailable&amp;nbsp;=&amp;nbsp;true;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;添加到商店
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.AddProduct(eventData);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;移除活动商品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;RemoveEventProducts()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;eventProduct&amp;nbsp;in&amp;nbsp;eventProducts)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;eventProductId&amp;nbsp;=&amp;nbsp;$&amp;quot;{eventProduct.originalProduct.productId}_event&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.RemoveProduct(eventProductId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Update()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查活动是否结束
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(isEventActive&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;Time.time&amp;nbsp;-&amp;nbsp;eventStartTime&amp;nbsp;&amp;gt;=&amp;nbsp;eventDuration)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EndEvent();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取活动剩余时间
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;GetEventRemainingTime()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!isEventActive)&amp;nbsp;return&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;Mathf.Max(0,&amp;nbsp;eventDuration&amp;nbsp;-&amp;nbsp;(Time.time&amp;nbsp;-&amp;nbsp;eventStartTime));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}[System.Serializable]public&amp;nbsp;class&amp;nbsp;EventProduct{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ProductData&amp;nbsp;originalProduct;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;eventDiscount;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 购买安全与验证&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;对于真实货币购买，需要添加安全验证机制：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ll4942m&quot; data-popupid=&quot;ll4942m&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8dayncf&quot; data-popupid=&quot;8dayncf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fei6t2n&quot; data-popupid=&quot;fei6t2n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;x8g5hzf&quot; data-popupid=&quot;x8g5hzf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ucqfy24&quot; data-popupid=&quot;ucqfy24&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;PurchaseValidator&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;验证内购交易（示例）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;ValidateIAPurchase(string&amp;nbsp;productId,&amp;nbsp;string&amp;nbsp;transactionId,&amp;nbsp;string&amp;nbsp;receipt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#if&amp;nbsp;UNITY_EDITOR
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;编辑器模式下直接返回成功
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应发送到服务器验证
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartCoroutine(ValidatePurchaseCoroutine(productId,&amp;nbsp;transactionId,&amp;nbsp;receipt));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;&amp;nbsp;//&amp;nbsp;异步验证，结果通过回调返回
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#endif
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;服务器验证协程
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;IEnumerator&amp;nbsp;ValidatePurchaseCoroutine(string&amp;nbsp;productId,&amp;nbsp;string&amp;nbsp;transactionId,&amp;nbsp;string&amp;nbsp;receipt)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建验证请求
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WWWForm&amp;nbsp;form&amp;nbsp;=&amp;nbsp;new&amp;nbsp;WWWForm();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;form.AddField(&amp;quot;productId&amp;quot;,&amp;nbsp;productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;form.AddField(&amp;quot;transactionId&amp;quot;,&amp;nbsp;transactionId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;form.AddField(&amp;quot;receipt&amp;quot;,&amp;nbsp;receipt);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;form.AddField(&amp;quot;userId&amp;quot;,&amp;nbsp;PlayerPrefs.GetString(&amp;quot;UserId&amp;quot;));

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发送到验证服务器
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;using&amp;nbsp;(UnityWebRequest&amp;nbsp;www&amp;nbsp;=&amp;nbsp;UnityWebRequest.Post(&amp;quot;https://yourserver.com/validate_purchase&amp;quot;,&amp;nbsp;form))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;yield&amp;nbsp;return&amp;nbsp;www.SendWebRequest();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(www.result&amp;nbsp;==&amp;nbsp;UnityWebRequest.Result.Success)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;解析验证结果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;string&amp;nbsp;response&amp;nbsp;=&amp;nbsp;www.downloadHandler.text;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(response.Contains(&amp;quot;valid&amp;quot;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;验证成功，发放物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseValidated(productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;验证失败
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseInvalidated(productId,&amp;nbsp;&amp;quot;服务器验证失败&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;网络错误
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnPurchaseInvalidated(productId,&amp;nbsp;&amp;quot;网络错误&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买验证成功
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnPurchaseValidated(string&amp;nbsp;productId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ProductData&amp;nbsp;product&amp;nbsp;=&amp;nbsp;ShopManager.Instance.GetProductById(productId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(product&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;发放物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShopManager.Instance.GrantProductItems(product,&amp;nbsp;1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新购买记录等
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;购买验证失败
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnPurchaseInvalidated(string&amp;nbsp;productId,&amp;nbsp;string&amp;nbsp;reason)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.LogError($&amp;quot;购买验证失败:&amp;nbsp;{productId},&amp;nbsp;原因:&amp;nbsp;{reason}&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;通知玩家购买失败
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、优化与体验建议&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 性能优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;商品列表使用对象池管理 UI 元素，避免频繁创建销毁&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;大量商品时实现分页加载或滚动加载&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;商品图标使用图集（Sprite Atlas）减少 Draw Call&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;复杂的商品筛选和排序在后台线程处理&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 购买体验优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;重要购买添加二次确认步骤，防止误操作&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;购买过程中显示加载动画，明确操作状态&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;货币不足时提供快捷充值入口&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;支持批量购买，减少重复操作&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;限购商品明确显示剩余购买次数&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;折扣商品使用醒目的视觉标记&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 经济平衡要点&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;确保商品价格与价值匹配，避免性价比失衡&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;不同类型货币的兑换比例保持稳定&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;定期更新商品列表，保持商店新鲜感&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;活动商品提供更高性价比，促进参与度&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;内购商品定价符合目标市场消费水平&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;七、结语&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文实现的物品购买系统提供了一个完整的基础框架，涵盖了商品管理、货币系统、购买流程和 UI 展示等核心功能。该系统采用数据驱动设计，通过 ScriptableObject 配置商品信息，使得后续扩展和调整变得简单高效。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在实际项目中，可以根据游戏类型和商业模式进一步扩展该系统，例如添加会员专属商品、限时抢购、积分系统、推荐算法等功能。关键是要平衡游戏内经济，提供良好的购买体验，同时确保交易安全可靠。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;希望这个购买系统方案能为你的 Unity 项目提供有价值的参考，祝开发顺利！&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 27 Nov 2025 18:03:04 +0800</pubDate></item><item><title>Unity 开发实战：构建灵活可扩展的技能系统</title><link>https://songhongblog.top/?id=27</link><description>&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;技能系统是动作角色扮演、MOBA、战斗类游戏的核心玩法组件，一个设计良好的技能系统能为游戏带来丰富的战斗体验和策略深度。本文将详细介绍如何在 Unity 中实现一套灵活可扩展的技能系统，包括技能释放、冷却、效果执行和资源消耗等核心功能。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、技能系统核心需求分析&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一个完善的技能系统应包含以下核心要素：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;多类型技能支持（主动、被动、即时、持续）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能资源消耗机制（法力、能量、怒气等）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;冷却时间管理&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能效果系统（伤害、治疗、 buff、 debuff）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能目标选择（单体、群体、自我、区域）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能升级与强化&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能释放动画与特效&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能 UI 展示（图标、冷却、资源）&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、数据结构设计&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;采用 ScriptableObject 存储技能配置数据，结合运行时实例类管理技能状态，实现数据与逻辑分离。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 技能基础定义&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f3m32pk&quot; data-popupid=&quot;f3m32pk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ef1om7u&quot; data-popupid=&quot;ef1om7u&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;lkxf4qd&quot; data-popupid=&quot;lkxf4qd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;nkzs5zy&quot; data-popupid=&quot;nkzs5zy&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;1e3y5p5&quot; data-popupid=&quot;1e3y5p5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;技能类型public&amp;nbsp;enum&amp;nbsp;SkillType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Active,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;主动技能（需要手动释放）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Passive,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;被动技能（自动生效）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Toggle&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;开关技能（切换状态）}//&amp;nbsp;技能目标类型public&amp;nbsp;enum&amp;nbsp;TargetType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Self,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;自身
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SingleEnemy,&amp;nbsp;//&amp;nbsp;单个敌人
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SingleAlly,&amp;nbsp;&amp;nbsp;//&amp;nbsp;单个盟友
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Area,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;区域
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Cone,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;扇形范围
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Line&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;直线范围}//&amp;nbsp;技能资源类型public&amp;nbsp;enum&amp;nbsp;ResourceType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Mana,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;法力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Stamina,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;耐力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Rage,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;怒气
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Energy,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;能量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;None&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;无消耗}//&amp;nbsp;技能效果类型public&amp;nbsp;enum&amp;nbsp;EffectType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Damage,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;伤害
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Heal,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;治疗
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Buff,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;增益
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debuff,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;减益
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CrowdControl,//&amp;nbsp;控制
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Teleport,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;传送
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Summon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;召唤}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 技能配置数据（ScriptableObject）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;84uuiha&quot; data-popupid=&quot;84uuiha&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hcp42n8&quot; data-popupid=&quot;hcp42n8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;p2eblfi&quot; data-popupid=&quot;p2eblfi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;z85iryg&quot; data-popupid=&quot;z85iryg&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6hkg9fu&quot; data-popupid=&quot;6hkg9fu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System.Collections.Generic;[CreateAssetMenu(fileName&amp;nbsp;=&amp;nbsp;&amp;quot;SkillData&amp;quot;,&amp;nbsp;menuName&amp;nbsp;=&amp;nbsp;&amp;quot;Skill/SkillData&amp;quot;)]public&amp;nbsp;class&amp;nbsp;SkillData&amp;nbsp;:&amp;nbsp;ScriptableObject{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;基础信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;skillName;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;description;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能描述
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Sprite&amp;nbsp;icon;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能图标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;skillId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillType&amp;nbsp;skillType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;requiredLevel;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;所需等级

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;目标设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;TargetType&amp;nbsp;targetType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;目标类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;range;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能范围
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;radius;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;范围半径（区域技能）

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;消耗设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ResourceType&amp;nbsp;resourceType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;资源类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;resourceCost;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;资源消耗

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;冷却设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;cooldown;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;冷却时间（秒）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;globalCooldown;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;公共冷却时间（秒）

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;效果设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;SkillEffectData&amp;gt;&amp;nbsp;effects;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能效果列表

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;动画与特效&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;castAnimation;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;施法动画名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;GameObject&amp;nbsp;castEffectPrefab;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;施法特效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;GameObject&amp;nbsp;hitEffectPrefab;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;命中特效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;AudioClip&amp;nbsp;castSound;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;施法音效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;AudioClip&amp;nbsp;hitSound;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;命中音效

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;升级数据&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillData&amp;nbsp;nextLevel;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;下一级技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;maxLevel&amp;nbsp;=&amp;nbsp;5;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;最大等级}//&amp;nbsp;技能效果数据[System.Serializable]public&amp;nbsp;class&amp;nbsp;SkillEffectData{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EffectType&amp;nbsp;effectType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;效果类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;value;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;基础值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;valuePerLevel;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;每级增加值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;duration;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;持续时间（秒，0为即时）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;chance;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发概率（0-1）}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 技能运行时数据&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;4obtfcw&quot; data-popupid=&quot;4obtfcw&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hn2lx21&quot; data-popupid=&quot;hn2lx21&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;a6ke5a9&quot; data-popupid=&quot;a6ke5a9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8imd8p4&quot; data-popupid=&quot;8imd8p4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dftos00&quot; data-popupid=&quot;dftos00&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;SkillInstance{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillData&amp;nbsp;data;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能配置数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;level;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;cooldownRemaining;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;剩余冷却时间
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isUnlocked;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否解锁
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isActive;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否激活（开关技能）

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillInstance(SkillData&amp;nbsp;data)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.data&amp;nbsp;=&amp;nbsp;data;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.level&amp;nbsp;=&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.cooldownRemaining&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.isUnlocked&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.isActive&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查技能是否可释放
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;CanCast(ISkillCaster&amp;nbsp;caster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否解锁
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!isUnlocked)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(cooldownRemaining&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!caster.HasEnoughResource(data.resourceType,&amp;nbsp;data.resourceCost))&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否是被动技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(data.skillType&amp;nbsp;==&amp;nbsp;SkillType.Passive)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新冷却时间
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;UpdateCooldown(float&amp;nbsp;deltaTime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(cooldownRemaining&amp;nbsp;&amp;gt;&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownRemaining&amp;nbsp;=&amp;nbsp;Mathf.Max(0,&amp;nbsp;cooldownRemaining&amp;nbsp;-&amp;nbsp;deltaTime);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;升级技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;Upgrade()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(level&amp;nbsp;&amp;lt;&amp;nbsp;data.maxLevel&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;data.nextLevel&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data&amp;nbsp;=&amp;nbsp;data.nextLevel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;level++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;开始冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;StartCooldown()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownRemaining&amp;nbsp;=&amp;nbsp;data.cooldown;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、技能系统核心逻辑实现&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 技能管理器（单例模式）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;负责技能的整体管理，包括学习、升级、冷却和释放逻辑。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5i7j5ye&quot; data-popupid=&quot;5i7j5ye&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;s672p0r&quot; data-popupid=&quot;s672p0r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;cn4vqhq&quot; data-popupid=&quot;cn4vqhq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;d4x2ngx&quot; data-popupid=&quot;d4x2ngx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;y6shr6s&quot; data-popupid=&quot;y6shr6s&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System.Collections.Generic;public&amp;nbsp;class&amp;nbsp;SkillManager&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;SkillManager&amp;nbsp;Instance&amp;nbsp;{&amp;nbsp;get;&amp;nbsp;private&amp;nbsp;set;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Dictionary&amp;lt;int,&amp;nbsp;SkillInstance&amp;gt;&amp;nbsp;skills&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;int,&amp;nbsp;SkillInstance&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;float&amp;nbsp;globalCooldownRemaining&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;ISkillCaster&amp;nbsp;currentCaster;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;事件定义
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;delegate&amp;nbsp;void&amp;nbsp;SkillCastDelegate(SkillInstance&amp;nbsp;skill,&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;SkillCastDelegate&amp;nbsp;OnSkillCast;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;System.Action&amp;lt;float&amp;gt;&amp;nbsp;OnGlobalCooldownChanged;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;System.Action&amp;lt;int&amp;gt;&amp;nbsp;OnSkillUpgraded;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Awake()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(Instance&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Instance&amp;nbsp;=&amp;nbsp;this;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DontDestroyOnLoad(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化技能管理器
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize(ISkillCaster&amp;nbsp;caster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster&amp;nbsp;=&amp;nbsp;caster;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skills.Clear();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;学习技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;LearnSkill(SkillData&amp;nbsp;skillData)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!skills.ContainsKey(skillData.skillId))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SkillInstance&amp;nbsp;newSkill&amp;nbsp;=&amp;nbsp;new&amp;nbsp;SkillInstance(skillData);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;newSkill.isUnlocked&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;被动技能立即生效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skillData.skillType&amp;nbsp;==&amp;nbsp;SkillType.Passive)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyPassiveEffects(newSkill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skills.Add(skillData.skillId,&amp;nbsp;newSkill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取技能实例
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillInstance&amp;nbsp;GetSkill(int&amp;nbsp;skillId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skills.TryGetValue(skillId,&amp;nbsp;out&amp;nbsp;SkillInstance&amp;nbsp;skill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;skill;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取所有技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;SkillInstance&amp;gt;&amp;nbsp;GetAllSkills()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;new&amp;nbsp;List&amp;lt;SkillInstance&amp;gt;(skills.Values);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;升级技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;UpgradeSkill(int&amp;nbsp;skillId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skills.TryGetValue(skillId,&amp;nbsp;out&amp;nbsp;SkillInstance&amp;nbsp;skill))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;upgraded&amp;nbsp;=&amp;nbsp;skill.Upgrade();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(upgraded)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnSkillUpgraded?.Invoke(skillId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;尝试释放技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;CastSkill(int&amp;nbsp;skillId,&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查公共冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(globalCooldownRemaining&amp;nbsp;&amp;gt;&amp;nbsp;0)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取技能
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!skills.TryGetValue(skillId,&amp;nbsp;out&amp;nbsp;SkillInstance&amp;nbsp;skill))&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否可释放
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!skill.CanCast(currentCaster))&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查目标是否有效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!ValidateTargets(skill,&amp;nbsp;targets))&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.ConsumeResource(skill.data.resourceType,&amp;nbsp;skill.data.resourceCost);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;开始冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skill.StartCooldown();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;globalCooldownRemaining&amp;nbsp;=&amp;nbsp;skill.data.globalCooldown;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放动画和特效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PlaySkillVFX(skill);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用技能效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplySkillEffects(skill,&amp;nbsp;targets);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnSkillCast?.Invoke(skill,&amp;nbsp;targets);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;验证目标是否有效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;bool&amp;nbsp;ValidateTargets(SkillInstance&amp;nbsp;skill,&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据技能目标类型验证目标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.data.targetType&amp;nbsp;==&amp;nbsp;TargetType.Self)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;targets&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;targets.Count&amp;nbsp;==&amp;nbsp;1&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;targets[0]&amp;nbsp;==&amp;nbsp;currentCaster.GetCasterGameObject();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(targets&amp;nbsp;==&amp;nbsp;null&amp;nbsp;||&amp;nbsp;targets.Count&amp;nbsp;==&amp;nbsp;0)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;可以添加更多目标验证逻辑（距离、阵营等）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用技能效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplySkillEffects(SkillInstance&amp;nbsp;skill,&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;target&amp;nbsp;in&amp;nbsp;targets)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;effectData&amp;nbsp;in&amp;nbsp;skill.data.effects)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查概率
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(Random.Range(0f,&amp;nbsp;1f)&amp;nbsp;&amp;gt;&amp;nbsp;effectData.chance)&amp;nbsp;continue;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据效果类型应用效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyEffect(effectData,&amp;nbsp;skill.level,&amp;nbsp;currentCaster.GetCasterGameObject(),&amp;nbsp;target);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用单个效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyEffect(SkillEffectData&amp;nbsp;data,&amp;nbsp;int&amp;nbsp;skillLevel,&amp;nbsp;GameObject&amp;nbsp;caster,&amp;nbsp;GameObject&amp;nbsp;target)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算最终效果值（基础值&amp;nbsp;+&amp;nbsp;等级加成）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;finalValue&amp;nbsp;=&amp;nbsp;data.value&amp;nbsp;+&amp;nbsp;(data.valuePerLevel&amp;nbsp;*&amp;nbsp;(skillLevel&amp;nbsp;-&amp;nbsp;1));

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;nbsp;(data.effectType)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Damage:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyDamage(target,&amp;nbsp;finalValue);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Heal:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyHeal(target,&amp;nbsp;finalValue);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Buff:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyBuff(target,&amp;nbsp;data,&amp;nbsp;finalValue);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Debuff:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyDebuff(target,&amp;nbsp;data,&amp;nbsp;finalValue);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.CrowdControl:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyCrowdControl(target,&amp;nbsp;data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;其他效果类型...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用被动技能效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyPassiveEffects(SkillInstance&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;为被动技能添加持续效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;effectData&amp;nbsp;in&amp;nbsp;skill.data.effects)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyEffect(effectData,&amp;nbsp;skill.level,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.GetCasterGameObject(),&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.GetCasterGameObject());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放技能视觉特效和音效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;PlaySkillVFX(SkillInstance&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放施法动画
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.PlayAnimation(skill.data.castAnimation);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放施法特效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.data.castEffectPrefab&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GameObject&amp;nbsp;effect&amp;nbsp;=&amp;nbsp;Instantiate(skill.data.castEffectPrefab,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.GetCasterGameObject().transform.position,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Quaternion.identity);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(effect,&amp;nbsp;2f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放施法音效
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.data.castSound&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AudioSource.PlayClipAtPoint(skill.data.castSound,&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentCaster.GetCasterGameObject().transform.position);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Update()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新所有技能冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;skill&amp;nbsp;in&amp;nbsp;skills.Values)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skill.UpdateCooldown(Time.deltaTime);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新公共冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(globalCooldownRemaining&amp;nbsp;&amp;gt;&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;globalCooldownRemaining&amp;nbsp;=&amp;nbsp;Mathf.Max(0,&amp;nbsp;globalCooldownRemaining&amp;nbsp;-&amp;nbsp;Time.deltaTime);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnGlobalCooldownChanged?.Invoke(globalCooldownRemaining);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用伤害（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyDamage(GameObject&amp;nbsp;target,&amp;nbsp;float&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HealthSystem&amp;nbsp;health&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;HealthSystem&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(health&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;health.TakeDamage(Mathf.RoundToInt(amount));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用治疗（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyHeal(GameObject&amp;nbsp;target,&amp;nbsp;float&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;HealthSystem&amp;nbsp;health&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;HealthSystem&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(health&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;health.Heal(Mathf.RoundToInt(amount));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用增益效果（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyBuff(GameObject&amp;nbsp;target,&amp;nbsp;SkillEffectData&amp;nbsp;data,&amp;nbsp;float&amp;nbsp;value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BuffSystem&amp;nbsp;buffSystem&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;BuffSystem&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(buffSystem&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建并添加buff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Buff&amp;nbsp;buff&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Buff(data.effectType,&amp;nbsp;value,&amp;nbsp;data.duration);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buffSystem.AddBuff(buff);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用减益效果（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyDebuff(GameObject&amp;nbsp;target,&amp;nbsp;SkillEffectData&amp;nbsp;data,&amp;nbsp;float&amp;nbsp;value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;BuffSystem&amp;nbsp;buffSystem&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;BuffSystem&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(buffSystem&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建并添加debuff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Buff&amp;nbsp;debuff&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Buff(data.effectType,&amp;nbsp;value,&amp;nbsp;data.duration,&amp;nbsp;isDebuff:&amp;nbsp;true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;buffSystem.AddBuff(debuff);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用控制效果（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyCrowdControl(GameObject&amp;nbsp;target,&amp;nbsp;SkillEffectData&amp;nbsp;data)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ControlSystem&amp;nbsp;controlSystem&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;ControlSystem&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(controlSystem&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;controlSystem.ApplyControl(data.effectType,&amp;nbsp;data.duration);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 技能释放者接口&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;定义技能释放者需要实现的功能，使系统支持多种角色释放技能。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0a85c9i&quot; data-popupid=&quot;0a85c9i&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;v6jeov7&quot; data-popupid=&quot;v6jeov7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;v3a2k5n&quot; data-popupid=&quot;v3a2k5n&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;g3hdmjt&quot; data-popupid=&quot;g3hdmjt&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e91dut9&quot; data-popupid=&quot;e91dut9&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;interface&amp;nbsp;ISkillCaster{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否有足够的资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;HasEnoughResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;ConsumeResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;播放动画
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;void&amp;nbsp;PlayAnimation(string&amp;nbsp;animationName);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取释放者游戏对象
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GameObject&amp;nbsp;GetCasterGameObject();}//&amp;nbsp;玩家技能释放者实现public&amp;nbsp;class&amp;nbsp;PlayerSkillCaster&amp;nbsp;:&amp;nbsp;MonoBehaviour,&amp;nbsp;ISkillCaster{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;ResourceSystem&amp;nbsp;resourceSystem;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Animator&amp;nbsp;animator;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;HasEnoughResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;resourceSystem.HasEnoughResource(type,&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceSystem.ConsumeResource(type,&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;PlayAnimation(string&amp;nbsp;animationName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;animator.Play(animationName);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;GameObject&amp;nbsp;GetCasterGameObject()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;gameObject;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 资源系统（技能消耗）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;0mdejcd&quot; data-popupid=&quot;0mdejcd&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;e49ohs4&quot; data-popupid=&quot;e49ohs4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ukr0f5i&quot; data-popupid=&quot;ukr0f5i&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;b82f7r8&quot; data-popupid=&quot;b82f7r8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;y1mtkmi&quot; data-popupid=&quot;y1mtkmi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;public&amp;nbsp;class&amp;nbsp;ResourceSystem&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[System.Serializable]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;class&amp;nbsp;Resource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;ResourceType&amp;nbsp;type;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;current;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;max;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;regenRate;&amp;nbsp;//&amp;nbsp;每秒恢复量
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Resource[]&amp;nbsp;resources;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否有足够资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;HasEnoughResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Resource&amp;nbsp;resource&amp;nbsp;=&amp;nbsp;GetResource(type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;resource&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;resource.current&amp;nbsp;&amp;gt;=&amp;nbsp;amount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Resource&amp;nbsp;resource&amp;nbsp;=&amp;nbsp;GetResource(type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(resource&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resource.current&amp;nbsp;=&amp;nbsp;Mathf.Max(0,&amp;nbsp;resource.current&amp;nbsp;-&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnResourceChanged?.Invoke(type,&amp;nbsp;resource.current,&amp;nbsp;resource.max);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;增加资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;AddResource(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;amount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Resource&amp;nbsp;resource&amp;nbsp;=&amp;nbsp;GetResource(type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(resource&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resource.current&amp;nbsp;=&amp;nbsp;Mathf.Min(resource.max,&amp;nbsp;resource.current&amp;nbsp;+&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnResourceChanged?.Invoke(type,&amp;nbsp;resource.current,&amp;nbsp;resource.max);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取资源
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Resource&amp;nbsp;GetResource(ResourceType&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;res&amp;nbsp;in&amp;nbsp;resources)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(res.type&amp;nbsp;==&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;res;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Update()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;资源自动恢复
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;res&amp;nbsp;in&amp;nbsp;resources)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(res.current&amp;nbsp;&amp;lt;&amp;nbsp;res.max&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;res.regenRate&amp;nbsp;&amp;gt;&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;regen&amp;nbsp;=&amp;nbsp;res.regenRate&amp;nbsp;*&amp;nbsp;Time.deltaTime;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;before&amp;nbsp;=&amp;nbsp;res.current;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;res.current&amp;nbsp;=&amp;nbsp;Mathf.Min(res.max,&amp;nbsp;res.current&amp;nbsp;+&amp;nbsp;Mathf.RoundToInt(regen));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(res.current&amp;nbsp;!=&amp;nbsp;before)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnResourceChanged?.Invoke(res.type,&amp;nbsp;res.current,&amp;nbsp;res.max);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;资源变化事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;delegate&amp;nbsp;void&amp;nbsp;ResourceChangedDelegate(ResourceType&amp;nbsp;type,&amp;nbsp;int&amp;nbsp;current,&amp;nbsp;int&amp;nbsp;max);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;ResourceChangedDelegate&amp;nbsp;OnResourceChanged;}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、技能 UI 实现&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;技能 UI 负责展示技能图标、冷却状态和资源消耗，提供技能释放入口。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;myjf5fk&quot; data-popupid=&quot;myjf5fk&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;06hio8x&quot; data-popupid=&quot;06hio8x&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8pg4m93&quot; data-popupid=&quot;8pg4m93&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;32m0ny0&quot; data-popupid=&quot;32m0ny0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zukyzoc&quot; data-popupid=&quot;zukyzoc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;UnityEngine.UI;using&amp;nbsp;TMPro;using&amp;nbsp;System.Collections.Generic;public&amp;nbsp;class&amp;nbsp;SkillUI&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;技能栏&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;List&amp;lt;SkillSlot&amp;gt;&amp;nbsp;skillSlots;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;技能详情面板&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;detailPanel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;skillNameText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;descriptionText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;levelText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;costText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;cooldownText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;upgradeButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;SkillInstance&amp;nbsp;selectedSkill;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Start()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化技能槽
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;slot&amp;nbsp;in&amp;nbsp;skillSlots)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;slot.Initialize();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;注册事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SkillManager.Instance.OnSkillCast&amp;nbsp;+=&amp;nbsp;UpdateSkillCooldowns;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;upgradeButton.onClick.AddListener(OnUpgradeButtonClicked);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏详情面板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Update()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新技能冷却显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateAllSkillCooldowns();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化技能UI
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;InitializeSkills(List&amp;lt;SkillInstance&amp;gt;&amp;nbsp;skills)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;0;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;skills.Count&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;i&amp;nbsp;&amp;lt;&amp;nbsp;skillSlots.Count;&amp;nbsp;i++)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skillSlots[i].SetSkill(skills[i],&amp;nbsp;OnSkillSlotClicked);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新所有技能冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateAllSkillCooldowns()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;slot&amp;nbsp;in&amp;nbsp;skillSlots)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;slot.UpdateCooldownDisplay();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新指定技能冷却
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateSkillCooldowns(SkillInstance&amp;nbsp;skill,&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;slot&amp;nbsp;in&amp;nbsp;skillSlots)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(slot.Skill&amp;nbsp;==&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;slot.UpdateCooldownDisplay();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;技能槽点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnSkillSlotClicked(SkillInstance&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill&amp;nbsp;==&amp;nbsp;null)&amp;nbsp;return;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;selectedSkill&amp;nbsp;=&amp;nbsp;skill;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowSkillDetails(skill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示技能详情
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ShowSkillDetails(SkillInstance&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skillNameText.text&amp;nbsp;=&amp;nbsp;skill.data.skillName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;descriptionText.text&amp;nbsp;=&amp;nbsp;skill.data.description;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;levelText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;等级:&amp;nbsp;{skill.level}/{skill.data.maxLevel}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;costText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{skill.data.resourceCost}&amp;nbsp;{skill.data.resourceType}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;冷却:&amp;nbsp;{skill.data.cooldown}秒&amp;quot;;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新升级按钮状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;upgradeButton.interactable&amp;nbsp;=&amp;nbsp;skill.level&amp;nbsp;&amp;lt;&amp;nbsp;skill.data.maxLevel&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;skill.data.nextLevel&amp;nbsp;!=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;升级按钮点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnUpgradeButtonClicked()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedSkill&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;upgraded&amp;nbsp;=&amp;nbsp;SkillManager.Instance.UpgradeSkill(selectedSkill.data.skillId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(upgraded)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowSkillDetails(selectedSkill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}//&amp;nbsp;技能槽UI组件public&amp;nbsp;class&amp;nbsp;SkillSlot&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;cooldownOverlay;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;keybindText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;levelText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;resourceCostIcon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;resourceCostText;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;SkillInstance&amp;nbsp;skill;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Action&amp;lt;SkillInstance&amp;gt;&amp;nbsp;onClick;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;button;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;SkillInstance&amp;nbsp;Skill&amp;nbsp;=&amp;gt;&amp;nbsp;skill;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;button&amp;nbsp;=&amp;nbsp;GetComponent&amp;lt;Button&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;button.onClick.AddListener(OnClick);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Hide();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;SetSkill(SkillInstance&amp;nbsp;skillInstance,&amp;nbsp;Action&amp;lt;SkillInstance&amp;gt;&amp;nbsp;onClickAction)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skill&amp;nbsp;=&amp;nbsp;skillInstance;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onClick&amp;nbsp;=&amp;nbsp;onClickAction;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置图标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.sprite&amp;nbsp;=&amp;nbsp;skill.data.icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.enabled&amp;nbsp;=&amp;nbsp;true;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置快捷键文本
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;keybindText.text&amp;nbsp;=&amp;nbsp;GetKeybindText();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;levelText.text&amp;nbsp;=&amp;nbsp;skill.level.ToString();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置资源消耗
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.data.resourceType&amp;nbsp;!=&amp;nbsp;ResourceType.None)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostIcon.enabled&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostText.text&amp;nbsp;=&amp;nbsp;skill.data.resourceCost.ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;可以根据资源类型设置不同图标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostIcon.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostText.text&amp;nbsp;=&amp;nbsp;&amp;quot;&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示技能槽
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gameObject.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Hide()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownOverlay.fillAmount&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;keybindText.text&amp;nbsp;=&amp;nbsp;&amp;quot;&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;levelText.text&amp;nbsp;=&amp;nbsp;&amp;quot;&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostIcon.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceCostText.text&amp;nbsp;=&amp;nbsp;&amp;quot;&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;gameObject.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnClick()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onClick?.Invoke(skill);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;主动技能尝试释放
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.data.skillType&amp;nbsp;==&amp;nbsp;SkillType.Active)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取目标（实际项目中需要实现目标选择逻辑）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets&amp;nbsp;=&amp;nbsp;GetSkillTargets(skill);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SkillManager.Instance.CastSkill(skill.data.skillId,&amp;nbsp;targets);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;开关技能切换状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(skill.data.skillType&amp;nbsp;==&amp;nbsp;SkillType.Toggle)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;skill.isActive&amp;nbsp;=&amp;nbsp;!skill.isActive;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新冷却显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;UpdateCooldownDisplay()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill&amp;nbsp;==&amp;nbsp;null)&amp;nbsp;return;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(skill.cooldownRemaining&amp;nbsp;&amp;gt;&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;cooldownPercent&amp;nbsp;=&amp;nbsp;skill.cooldownRemaining&amp;nbsp;/&amp;nbsp;skill.data.cooldown;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownOverlay.fillAmount&amp;nbsp;=&amp;nbsp;cooldownPercent;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cooldownOverlay.fillAmount&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取快捷键文本（示例）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;string&amp;nbsp;GetKeybindText()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应从输入系统获取绑定的按键
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;slotIndex&amp;nbsp;=&amp;nbsp;transform.GetSiblingIndex()&amp;nbsp;+&amp;nbsp;1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;slotIndex.ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取技能目标（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;GetSkillTargets(SkillInstance&amp;nbsp;skill)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;GameObject&amp;gt;&amp;nbsp;targets&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;GameObject&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据技能目标类型获取目标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;nbsp;(skill.data.targetType)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;TargetType.Self:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;targets.Add(SkillManager.Instance.GetCasterGameObject());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;TargetType.SingleEnemy:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应获取选中的敌人
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GameObject&amp;nbsp;target&amp;nbsp;=&amp;nbsp;FindClosestEnemy();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(target&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;targets.Add(target);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;其他目标类型...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;targets;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;查找最近的敌人（示例实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;FindClosestEnemy()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应实现敌人检测逻辑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、技能效果系统扩展&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. Buff/Debuff 系统&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;j864boi&quot; data-popupid=&quot;j864boi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;8l8m5mf&quot; data-popupid=&quot;8l8m5mf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;piwwo3b&quot; data-popupid=&quot;piwwo3b&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;5sfqcbj&quot; data-popupid=&quot;5sfqcbj&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;idtd70q&quot; data-popupid=&quot;idtd70q&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;Buff{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EffectType&amp;nbsp;effectType;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;value;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;duration;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;remainingTime;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isDebuff;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isPermanent;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Buff(EffectType&amp;nbsp;type,&amp;nbsp;float&amp;nbsp;value,&amp;nbsp;float&amp;nbsp;duration,&amp;nbsp;bool&amp;nbsp;isDebuff&amp;nbsp;=&amp;nbsp;false,&amp;nbsp;bool&amp;nbsp;isPermanent&amp;nbsp;=&amp;nbsp;false)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;effectType&amp;nbsp;=&amp;nbsp;type;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.value&amp;nbsp;=&amp;nbsp;value;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.duration&amp;nbsp;=&amp;nbsp;duration;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.remainingTime&amp;nbsp;=&amp;nbsp;duration;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.isDebuff&amp;nbsp;=&amp;nbsp;isDebuff;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.isPermanent&amp;nbsp;=&amp;nbsp;isPermanent;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;Update(float&amp;nbsp;deltaTime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;remainingTime&amp;nbsp;-=&amp;nbsp;deltaTime;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;remainingTime&amp;nbsp;&amp;lt;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}public&amp;nbsp;class&amp;nbsp;BuffSystem&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;Buff&amp;gt;&amp;nbsp;activeBuffs&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;Buff&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;添加buff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;AddBuff(Buff&amp;nbsp;buff)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否已有相同类型的buff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Buff&amp;nbsp;existing&amp;nbsp;=&amp;nbsp;activeBuffs.Find(b&amp;nbsp;=&amp;gt;&amp;nbsp;b.effectType&amp;nbsp;==&amp;nbsp;buff.effectType);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(existing&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新持续时间或叠加效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;existing.remainingTime&amp;nbsp;=&amp;nbsp;Mathf.Max(existing.remainingTime,&amp;nbsp;buff.remainingTime);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;existing.value&amp;nbsp;=&amp;nbsp;Mathf.Max(existing.value,&amp;nbsp;buff.value);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;activeBuffs.Add(buff);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyBuffEffects(buff,&amp;nbsp;true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;移除buff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;RemoveBuff(Buff&amp;nbsp;buff)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(activeBuffs.Remove(buff))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ApplyBuffEffects(buff,&amp;nbsp;false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用buff效果
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ApplyBuffEffects(Buff&amp;nbsp;buff,&amp;nbsp;bool&amp;nbsp;apply)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;value&amp;nbsp;=&amp;nbsp;apply&amp;nbsp;?&amp;nbsp;buff.value&amp;nbsp;:&amp;nbsp;-buff.value;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;nbsp;(buff.effectType)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Buff:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用攻击力加成等
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetComponent&amp;lt;StatSystem&amp;gt;().ModifyStat(StatType.Attack,&amp;nbsp;value);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EffectType.Debuff:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用减速等
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetComponent&amp;lt;MovementSystem&amp;gt;().ModifySpeed(value&amp;nbsp;*&amp;nbsp;-0.01f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;其他效果类型...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Update()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新所有buff持续时间
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for&amp;nbsp;(int&amp;nbsp;i&amp;nbsp;=&amp;nbsp;activeBuffs.Count&amp;nbsp;-&amp;nbsp;1;&amp;nbsp;i&amp;nbsp;&amp;gt;=&amp;nbsp;0;&amp;nbsp;i--)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(activeBuffs[i].Update(Time.deltaTime))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RemoveBuff(activeBuffs[i]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、系统优化与平衡建议&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 性能优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;技能特效使用对象池管理，避免频繁创建和销毁&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;大范围技能的目标检测使用空间分区或碰撞体检测优化&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能更新逻辑采用帧延迟或间隔更新，减少每帧计算量&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;复杂的技能计算使用协程分帧处理&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 平衡设计要点&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;技能伤害与冷却时间正相关（高伤害技能应有更长冷却）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;资源消耗与技能效果平衡（强力技能消耗更多资源）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;确保技能组合有策略深度，避免单一最优解&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能升级收益应逐步提升，后期升级成本增加&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;不同类型技能应相互克制，形成平衡循环&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 玩家体验优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;技能释放有明确的反馈（特效、音效、震动）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;冷却时间可视化，让玩家清晰了解技能状态&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;技能范围使用指示器提前显示&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;关键技能添加施法前摇和打断机制&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;允许玩家自定义技能快捷键&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;七、结语&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文实现的技能系统采用了模块化、数据驱动的设计理念，通过 ScriptableObject 存储技能配置，使技能的扩展和调整变得简单直观。系统支持多种技能类型和效果，能满足不同类型游戏的需求。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在实际开发中，可以根据游戏的具体玩法进一步扩展这个基础框架，例如添加技能连招系统、技能分支选择、技能与装备的互动等特色功能。关键是保持系统的灵活性和可扩展性，以便在游戏开发过程中快速迭代和调整。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;希望这个技能系统方案能为你的 Unity 项目提供有价值的参考，祝开发顺利！&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 27 Nov 2025 18:02:44 +0800</pubDate></item><item><title>Unity 开发实战：装备系统与耐久度机制实现</title><link>https://songhongblog.top/?id=26</link><description>&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;装备系统是角色扮演、生存建造等类型游戏的核心玩法之一，而装备耐久度则为游戏增加了策略性和资源管理维度。本文将详细介绍如何在 Unity 中设计并实现一套完整的装备系统，包括装备属性、穿戴逻辑、耐久度消耗与修复机制，帮助你构建既丰富又平衡的装备玩法。&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一、装备系统核心需求分析&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;一个完善的装备系统应包含以下核心功能：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;多类型装备支持（武器、防具、饰品等）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备属性系统（攻击力、防御力、特殊效果）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;耐久度机制（使用消耗、损坏状态）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备穿戴与卸下逻辑&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;耐久度修复系统&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备品质与稀有度区分&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备 UI 展示（背包、穿戴界面）&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;二、数据结构设计&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;采用 ScriptableObject 存储装备配置数据，确保数据可配置且易于扩展，同时使用运行时数据类管理装备状态。&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;1. 装备类型与部位定义&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pkw5ud8&quot; data-popupid=&quot;pkw5ud8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;enp7nm3&quot; data-popupid=&quot;enp7nm3&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;jbjiqqu&quot; data-popupid=&quot;jbjiqqu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;70u5t4z&quot; data-popupid=&quot;70u5t4z&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;sitk1gq&quot; data-popupid=&quot;sitk1gq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;//&amp;nbsp;装备类型public&amp;nbsp;enum&amp;nbsp;EquipmentType{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Weapon,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;武器
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Armor,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;armor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Helmet,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;头盔
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Gloves,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;手套
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Boots,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;靴子
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Accessory&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;饰品}//&amp;nbsp;装备品质public&amp;nbsp;enum&amp;nbsp;EquipmentQuality{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Common,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;普通
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Uncommon,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;&amp;nbsp;uncommon
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Rare,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;稀有
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Epic,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;史诗
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Legendary&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;传说}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 装备配置数据（ScriptableObject）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9hvqt17&quot; data-popupid=&quot;9hvqt17&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;o2jrozf&quot; data-popupid=&quot;o2jrozf&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vib1cck&quot; data-popupid=&quot;vib1cck&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fsonnir&quot; data-popupid=&quot;fsonnir&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;edmc1up&quot; data-popupid=&quot;edmc1up&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;[CreateAssetMenu(fileName&amp;nbsp;=&amp;nbsp;&amp;quot;EquipmentData&amp;quot;,&amp;nbsp;menuName&amp;nbsp;=&amp;nbsp;&amp;quot;Equipment/EquipmentData&amp;quot;)]public&amp;nbsp;class&amp;nbsp;EquipmentData&amp;nbsp;:&amp;nbsp;ScriptableObject{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;基础信息&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;equipmentName;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;description;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备描述
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;Sprite&amp;nbsp;icon;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备图标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;GameObject&amp;nbsp;modelPrefab;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备模型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentType&amp;nbsp;equipmentType;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备类型
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentQuality&amp;nbsp;quality;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备品质

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;属性数值&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;attack;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;攻击力（武器）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;defense;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;防御力（防具）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;attackSpeed;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;攻击速度（武器）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;moveSpeedBonus;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;移动速度加成

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;耐久度设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;maxDurability;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;最大耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;durabilityLossPerUse;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;每次使用消耗的耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;durabilityLossPerHit;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;每次被击中消耗的耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;repairCost;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;修复成本
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;qualityDurabilityMultiplier;&amp;nbsp;&amp;nbsp;//&amp;nbsp;品质对耐久度的乘数

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;其他设置&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;requiredLevel;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;需求等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isPermanent;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否永久（不会损坏）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;canBeRepaired;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否可修复}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 装备实例数据（运行时状态）&lt;/h3&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;eqex9ml&quot; data-popupid=&quot;eqex9ml&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;kechbbh&quot; data-popupid=&quot;kechbbh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;gc9arz4&quot; data-popupid=&quot;gc9arz4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;pe665fi&quot; data-popupid=&quot;pe665fi&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;iopxw1y&quot; data-popupid=&quot;iopxw1y&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;[System.Serializable]public&amp;nbsp;class&amp;nbsp;EquipmentInstance{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;string&amp;nbsp;instanceId;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实例唯一ID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentData&amp;nbsp;data;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;关联的配置数据
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;currentDurability;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;当前耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;level;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;强化等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;isEquipped;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;是否已穿戴
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;durabilityLossMultiplier&amp;nbsp;=&amp;nbsp;1f;&amp;nbsp;//&amp;nbsp;耐久度消耗乘数（受品质影响）

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;构造函数
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentInstance(EquipmentData&amp;nbsp;data)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;instanceId&amp;nbsp;=&amp;nbsp;System.Guid.NewGuid().ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.data&amp;nbsp;=&amp;nbsp;data;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据品质计算实际最大耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;qualityAdjustedMax&amp;nbsp;=&amp;nbsp;Mathf.RoundToInt(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data.maxDurability&amp;nbsp;*&amp;nbsp;data.qualityDurabilityMultiplier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentDurability&amp;nbsp;=&amp;nbsp;qualityAdjustedMax;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;level&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isEquipped&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查装备是否可用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;IsUsable()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;永久装备或耐久度大于0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;data.isPermanent&amp;nbsp;||&amp;nbsp;currentDurability&amp;nbsp;&amp;gt;&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查装备是否损坏
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;IsBroken()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;!data.isPermanent&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;currentDurability&amp;nbsp;&amp;lt;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeDurability(bool&amp;nbsp;isAttack&amp;nbsp;=&amp;nbsp;true)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(data.isPermanent)&amp;nbsp;return;&amp;nbsp;//&amp;nbsp;永久装备不消耗耐久度

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据行为类型计算消耗
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;lossAmount&amp;nbsp;=&amp;nbsp;isAttack&amp;nbsp;?&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data.durabilityLossPerUse&amp;nbsp;:&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data.durabilityLossPerHit;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用乘数（强化等级可能降低消耗）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lossAmount&amp;nbsp;*=&amp;nbsp;durabilityLossMultiplier&amp;nbsp;*&amp;nbsp;(1&amp;nbsp;-&amp;nbsp;(level&amp;nbsp;*&amp;nbsp;0.05f));

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentDurability&amp;nbsp;=&amp;nbsp;Mathf.Max(0,&amp;nbsp;currentDurability&amp;nbsp;-&amp;nbsp;Mathf.RoundToInt(lossAmount));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;修复装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;Repair(int&amp;nbsp;amount&amp;nbsp;=&amp;nbsp;-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!data.canBeRepaired)&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;qualityAdjustedMax&amp;nbsp;=&amp;nbsp;Mathf.RoundToInt(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data.maxDurability&amp;nbsp;*&amp;nbsp;data.qualityDurabilityMultiplier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果未指定修复量，则修复至满耐久
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(amount&amp;nbsp;&amp;lt;=&amp;nbsp;0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentDurability&amp;nbsp;=&amp;nbsp;qualityAdjustedMax;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;currentDurability&amp;nbsp;=&amp;nbsp;Mathf.Min(qualityAdjustedMax,&amp;nbsp;currentDurability&amp;nbsp;+&amp;nbsp;amount);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取当前耐久度百分比
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;float&amp;nbsp;GetDurabilityPercentage()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;qualityAdjustedMax&amp;nbsp;=&amp;nbsp;Mathf.RoundToInt(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data.maxDurability&amp;nbsp;*&amp;nbsp;data.qualityDurabilityMultiplier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;(float)currentDurability&amp;nbsp;/&amp;nbsp;qualityAdjustedMax;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;三、装备系统核心逻辑实现&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 装备管理器（单例模式）&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;负责装备的整体管理，包括穿戴、卸下、耐久度更新等核心逻辑。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;37zeiak&quot; data-popupid=&quot;37zeiak&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2rf162d&quot; data-popupid=&quot;2rf162d&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;bdmglf2&quot; data-popupid=&quot;bdmglf2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;hq2tcil&quot; data-popupid=&quot;hq2tcil&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;zolwrf7&quot; data-popupid=&quot;zolwrf7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;System.Collections.Generic;using&amp;nbsp;System.Linq;public&amp;nbsp;class&amp;nbsp;EquipmentManager&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;static&amp;nbsp;EquipmentManager&amp;nbsp;Instance&amp;nbsp;{&amp;nbsp;get;&amp;nbsp;private&amp;nbsp;set;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备槽位（按类型存储当前穿戴的装备）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Dictionary&amp;lt;EquipmentType,&amp;nbsp;EquipmentInstance&amp;gt;&amp;nbsp;equippedItems&amp;nbsp;=&amp;nbsp;new&amp;nbsp;Dictionary&amp;lt;EquipmentType,&amp;nbsp;EquipmentInstance&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;所有拥有的装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;ownedEquipment&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;EquipmentInstance&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;事件定义
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;Action&amp;lt;EquipmentType,&amp;nbsp;EquipmentInstance&amp;gt;&amp;nbsp;OnEquipmentEquipped;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备穿戴时
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;Action&amp;lt;EquipmentType,&amp;nbsp;EquipmentInstance&amp;gt;&amp;nbsp;OnEquipmentUnequipped;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备卸下时
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;Action&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;OnDurabilityChanged;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;耐久度变化时
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;event&amp;nbsp;Action&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;OnEquipmentBroken;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备损坏时

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Awake()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(Instance&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Instance&amp;nbsp;=&amp;nbsp;this;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DontDestroyOnLoad(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化装备系统
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化装备槽位
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(EquipmentType&amp;nbsp;type&amp;nbsp;in&amp;nbsp;Enum.GetValues(typeof(EquipmentType)))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!equippedItems.ContainsKey(type))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equippedItems[type]&amp;nbsp;=&amp;nbsp;null;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;穿戴装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;EquipEquipment(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查装备是否可用
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;==&amp;nbsp;null&amp;nbsp;||&amp;nbsp;!equipment.IsUsable())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentType&amp;nbsp;type&amp;nbsp;=&amp;nbsp;equipment.data.equipmentType;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果该槽位已有装备，先卸下
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equippedItems[type]&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UnequipEquipment(type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;穿戴新装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.isEquipped&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equippedItems[type]&amp;nbsp;=&amp;nbsp;equipment;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发装备事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnEquipmentEquipped?.Invoke(type,&amp;nbsp;equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;卸下装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;UnequipEquipment(EquipmentType&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equippedItems.TryGetValue(type,&amp;nbsp;out&amp;nbsp;EquipmentInstance&amp;nbsp;equipment)&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;equipment&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.isEquipped&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equippedItems[type]&amp;nbsp;=&amp;nbsp;null;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发卸下事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnEquipmentUnequipped?.Invoke(type,&amp;nbsp;equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取指定类型的已装备物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentInstance&amp;nbsp;GetEquippedItem(EquipmentType&amp;nbsp;type)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equippedItems.TryGetValue(type,&amp;nbsp;out&amp;nbsp;EquipmentInstance&amp;nbsp;equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;equipment;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取所有已装备物品
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;GetAllEquippedItems()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;equippedItems.Values.Where(e&amp;nbsp;=&amp;gt;&amp;nbsp;e&amp;nbsp;!=&amp;nbsp;null).ToList();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗装备耐久度（攻击时）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeWeaponDurability()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;weapon&amp;nbsp;=&amp;nbsp;GetEquippedItem(EquipmentType.Weapon);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(weapon&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ConsumeEquipmentDurability(weapon,&amp;nbsp;true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;受到攻击时消耗防具耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeArmorDurability()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗所有防具类型的耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;armorTypes&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;EquipmentType&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentType.Armor,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentType.Helmet,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentType.Gloves,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentType.Boots&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;type&amp;nbsp;in&amp;nbsp;armorTypes)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;armor&amp;nbsp;=&amp;nbsp;GetEquippedItem(type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(armor&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ConsumeEquipmentDurability(armor,&amp;nbsp;false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗指定装备的耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;ConsumeEquipmentDurability(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;bool&amp;nbsp;isAttack)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;==&amp;nbsp;null&amp;nbsp;||&amp;nbsp;equipment.data.isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;记录消耗前的状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;wasBroken&amp;nbsp;=&amp;nbsp;equipment.IsBroken();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.ConsumeDurability(isAttack);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发耐久度变化事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnDurabilityChanged?.Invoke(equipment);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果装备刚损坏且之前未损坏，触发损坏事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!wasBroken&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;equipment.IsBroken())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnEquipmentBroken?.Invoke(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;修复装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;RepairEquipment(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;bool&amp;nbsp;fullRepair&amp;nbsp;=&amp;nbsp;true)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;==&amp;nbsp;null&amp;nbsp;||&amp;nbsp;!equipment.data.canBeRepaired)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;wasBroken&amp;nbsp;=&amp;nbsp;equipment.IsBroken();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;repaired&amp;nbsp;=&amp;nbsp;equipment.Repair(fullRepair&amp;nbsp;?&amp;nbsp;-1&amp;nbsp;:&amp;nbsp;0);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(repaired)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnDurabilityChanged?.Invoke(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果从损坏状态修复，触发装备事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(wasBroken&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;equipment.IsUsable())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment.isEquipped)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;OnEquipmentEquipped?.Invoke(equipment.data.equipmentType,&amp;nbsp;equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;repaired;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;添加装备到背包
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;AddEquipment(EquipmentData&amp;nbsp;data)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;newEquipment&amp;nbsp;=&amp;nbsp;new&amp;nbsp;EquipmentInstance(data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ownedEquipment.Add(newEquipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;从背包移除装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;RemoveEquipment(string&amp;nbsp;instanceId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;equipment&amp;nbsp;=&amp;nbsp;ownedEquipment.FirstOrDefault(e&amp;nbsp;=&amp;gt;&amp;nbsp;e.instanceId&amp;nbsp;==&amp;nbsp;instanceId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果是已装备的，先卸下
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment.isEquipped)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UnequipEquipment(equipment.data.equipmentType);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ownedEquipment.Remove(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取所有拥有的装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;List&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;GetAllOwnedEquipment()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;new&amp;nbsp;List&amp;lt;EquipmentInstance&amp;gt;(ownedEquipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算总防御力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;CalculateTotalDefense()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;totalDefense&amp;nbsp;=&amp;nbsp;0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;equipment&amp;nbsp;in&amp;nbsp;GetAllEquippedItems())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;totalDefense&amp;nbsp;+=&amp;nbsp;equipment.data.defense&amp;nbsp;*&amp;nbsp;(1&amp;nbsp;+&amp;nbsp;equipment.level&amp;nbsp;*&amp;nbsp;0.1f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;totalDefense;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算当前攻击力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;int&amp;nbsp;CalculateCurrentAttack()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;weapon&amp;nbsp;=&amp;nbsp;GetEquippedItem(EquipmentType.Weapon);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(weapon&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;weapon.IsUsable())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;weapon.data.attack&amp;nbsp;*&amp;nbsp;(1&amp;nbsp;+&amp;nbsp;weapon.level&amp;nbsp;*&amp;nbsp;0.1f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;1;&amp;nbsp;//&amp;nbsp;基础攻击力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 装备 UI 管理器&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;负责装备相关的 UI 展示与交互，包括装备栏、背包和详细信息面板。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;b3zlgvh&quot; data-popupid=&quot;b3zlgvh&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;dell4s0&quot; data-popupid=&quot;dell4s0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ptomr4u&quot; data-popupid=&quot;ptomr4u&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;6n3zsqv&quot; data-popupid=&quot;6n3zsqv&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;f5gd90m&quot; data-popupid=&quot;f5gd90m&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;using&amp;nbsp;UnityEngine;using&amp;nbsp;UnityEngine.UI;using&amp;nbsp;TMPro;using&amp;nbsp;System.Collections.Generic;public&amp;nbsp;class&amp;nbsp;EquipmentUIManager&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;装备栏&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;List&amp;lt;EquipmentSlotUI&amp;gt;&amp;nbsp;equipmentSlots&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;EquipmentSlotUI&amp;gt;();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;装备背包&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Transform&amp;nbsp;equipmentGrid;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;equipmentItemPrefab;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[Header(&amp;quot;装备详情面板&amp;quot;)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;detailPanel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;nameText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;typeText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;descriptionText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;statsText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Slider&amp;nbsp;durabilitySlider;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;durabilityText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;equipButton;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Button&amp;nbsp;repairButton;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;List&amp;lt;EquipmentItemUI&amp;gt;&amp;nbsp;equipmentItemUIs&amp;nbsp;=&amp;nbsp;new&amp;nbsp;List&amp;lt;EquipmentItemUI&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;EquipmentInstance&amp;nbsp;selectedEquipment;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Start()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;注册事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.OnEquipmentEquipped&amp;nbsp;+=&amp;nbsp;UpdateEquipmentSlot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.OnEquipmentUnequipped&amp;nbsp;+=&amp;nbsp;UpdateEquipmentSlot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.OnDurabilityChanged&amp;nbsp;+=&amp;nbsp;UpdateDurabilityDisplay;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;绑定按钮事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipButton.onClick.AddListener(OnEquipButtonClicked);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;repairButton.onClick.AddListener(OnRepairButtonClicked);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化装备槽
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;InitializeEquipmentSlots();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新装备背包
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshEquipmentInventory();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏详情面板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;初始化装备槽
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;InitializeEquipmentSlots()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;slot&amp;nbsp;in&amp;nbsp;equipmentSlots)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;slot.Initialize();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;刷新装备背包
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;RefreshEquipmentInventory()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;清除现有UI
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;ui&amp;nbsp;in&amp;nbsp;equipmentItemUIs)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Destroy(ui.gameObject);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipmentItemUIs.Clear();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;创建装备项UI
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;allEquipment&amp;nbsp;=&amp;nbsp;EquipmentManager.Instance.GetAllOwnedEquipment();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach&amp;nbsp;(var&amp;nbsp;equipment&amp;nbsp;in&amp;nbsp;allEquipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GameObject&amp;nbsp;itemObj&amp;nbsp;=&amp;nbsp;Instantiate(equipmentItemPrefab,&amp;nbsp;equipmentGrid);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentItemUI&amp;nbsp;itemUI&amp;nbsp;=&amp;nbsp;itemObj.GetComponent&amp;lt;EquipmentItemUI&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;itemUI.Initialize(equipment,&amp;nbsp;OnEquipmentItemClicked);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipmentItemUIs.Add(itemUI);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新装备槽显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateEquipmentSlot(EquipmentType&amp;nbsp;type,&amp;nbsp;EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;slot&amp;nbsp;=&amp;nbsp;equipmentSlots.FirstOrDefault(s&amp;nbsp;=&amp;gt;&amp;nbsp;s.EquipmentType&amp;nbsp;==&amp;nbsp;type);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(slot&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;slot.SetEquipment(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;同时更新背包中对应装备的状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;RefreshEquipmentInventory();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备项点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnEquipmentItemClicked(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;selectedEquipment&amp;nbsp;=&amp;nbsp;equipment;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowEquipmentDetails(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示装备详情
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ShowEquipmentDetails(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;==&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;detailPanel.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nameText.text&amp;nbsp;=&amp;nbsp;equipment.data.equipmentName;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;typeText.text&amp;nbsp;=&amp;nbsp;equipment.data.equipmentType.ToString();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;descriptionText.text&amp;nbsp;=&amp;nbsp;equipment.data.description;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示属性
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;statsText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;攻击力:&amp;nbsp;{equipment.data.attack}\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$&amp;quot;防御力:&amp;nbsp;{equipment.data.defense}\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$&amp;quot;攻击速度:&amp;nbsp;{equipment.data.attackSpeed}\n&amp;quot;&amp;nbsp;+
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$&amp;quot;移动加成:&amp;nbsp;{equipment.data.moveSpeedBonus&amp;nbsp;*&amp;nbsp;100}%&amp;quot;;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateDurabilityDisplay(equipment);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新按钮状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipButton.gameObject.SetActive(!equipment.isEquipped&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;equipment.IsUsable());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;repairButton.gameObject.SetActive(equipment.data.canBeRepaired&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.currentDurability&amp;nbsp;&amp;lt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Mathf.RoundToInt(equipment.data.maxDurability&amp;nbsp;*&amp;nbsp;equipment.data.qualityDurabilityMultiplier));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新耐久度显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;UpdateDurabilityDisplay(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment.data.isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilitySlider.gameObject.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.text&amp;nbsp;=&amp;nbsp;&amp;quot;永久&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilitySlider.gameObject.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;percentage&amp;nbsp;=&amp;nbsp;equipment.GetDurabilityPercentage();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilitySlider.value&amp;nbsp;=&amp;nbsp;percentage;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{equipment.currentDurability}/{Mathf.RoundToInt(equipment.data.maxDurability&amp;nbsp;*&amp;nbsp;equipment.data.qualityDurabilityMultiplier)}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据耐久度设置颜色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.2f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.red;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.5f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.yellow;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.green;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果当前显示的是该装备，更新详情面板
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedEquipment&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;selectedEquipment.instanceId&amp;nbsp;==&amp;nbsp;equipment.instanceId)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;repairButton.gameObject.SetActive(equipment.data.canBeRepaired&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.currentDurability&amp;nbsp;&amp;lt;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Mathf.RoundToInt(equipment.data.maxDurability&amp;nbsp;*&amp;nbsp;equipment.data.qualityDurabilityMultiplier));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;装备按钮点击
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnEquipButtonClicked()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedEquipment&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.EquipEquipment(selectedEquipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;修复按钮点击
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnRepairButtonClicked()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(selectedEquipment&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查是否有足够的修复资源（实际项目中应与资源系统交互）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;bool&amp;nbsp;hasEnoughResources&amp;nbsp;=&amp;nbsp;CheckRepairResources(selectedEquipment);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(hasEnoughResources)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗资源（实际项目中实现）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ConsumeRepairResources(selectedEquipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;修复装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.RepairEquipment(selectedEquipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;提示资源不足
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Debug.Log(&amp;quot;修复资源不足&amp;quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查修复资源（示例方法）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;bool&amp;nbsp;CheckRepairResources(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中应检查玩家是否拥有足够的修复材料
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗修复资源（示例方法）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ConsumeRepairResources(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实际项目中实现资源消耗逻辑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}//&amp;nbsp;装备槽UI组件public&amp;nbsp;class&amp;nbsp;EquipmentSlotUI&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;EquipmentType&amp;nbsp;equipmentType;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;durabilityBar;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;emptyIndicator;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;EquipmentType&amp;nbsp;EquipmentType&amp;nbsp;=&amp;gt;&amp;nbsp;equipmentType;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SetEquipment(null);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;SetEquipment(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.sprite&amp;nbsp;=&amp;nbsp;equipment.data.icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.enabled&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;emptyIndicator.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新耐久度条
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!equipment.data.isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.enabled&amp;nbsp;=&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;percentage&amp;nbsp;=&amp;nbsp;equipment.GetDurabilityPercentage();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.fillAmount&amp;nbsp;=&amp;nbsp;percentage;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置耐久度条颜色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.2f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.color&amp;nbsp;=&amp;nbsp;Color.red;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.5f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.color&amp;nbsp;=&amp;nbsp;Color.yellow;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.color&amp;nbsp;=&amp;nbsp;Color.green;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityBar.enabled&amp;nbsp;=&amp;nbsp;false;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;emptyIndicator.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}//&amp;nbsp;装备项UI组件public&amp;nbsp;class&amp;nbsp;EquipmentItemUI&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;nameText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;durabilityText;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;Image&amp;nbsp;qualityBorder;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;equippedIndicator;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;EquipmentInstance&amp;nbsp;equipment;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Action&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;onClickAction;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Initialize(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;Action&amp;lt;EquipmentInstance&amp;gt;&amp;nbsp;onClick)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.equipment&amp;nbsp;=&amp;nbsp;equipment;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this.onClickAction&amp;nbsp;=&amp;nbsp;onClick;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置图标和名称
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;icon.sprite&amp;nbsp;=&amp;nbsp;equipment.data.icon;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nameText.text&amp;nbsp;=&amp;nbsp;equipment.data.equipmentName;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置品质边框颜色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;qualityBorder.color&amp;nbsp;=&amp;nbsp;GetQualityColor(equipment.data.quality);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置耐久度显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment.data.isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.text&amp;nbsp;=&amp;nbsp;&amp;quot;永久&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;UpdateDurability();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;设置装备状态
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equippedIndicator.SetActive(equipment.isEquipped);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;绑定点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetComponent&amp;lt;Button&amp;gt;().onClick.AddListener(OnClick);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;更新耐久度显示
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;UpdateDurability()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment&amp;nbsp;!=&amp;nbsp;null&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;!equipment.data.isPermanent)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{equipment.currentDurability}/{Mathf.RoundToInt(equipment.data.maxDurability&amp;nbsp;*&amp;nbsp;equipment.data.qualityDurabilityMultiplier)}&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;根据耐久度设置颜色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;float&amp;nbsp;percentage&amp;nbsp;=&amp;nbsp;equipment.GetDurabilityPercentage();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.2f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.red;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&amp;nbsp;if&amp;nbsp;(percentage&amp;nbsp;&amp;lt;&amp;nbsp;0.5f)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.yellow;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;durabilityText.color&amp;nbsp;=&amp;nbsp;Color.green;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;点击事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;OnClick()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;onClickAction?.Invoke(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;获取品质对应的颜色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;Color&amp;nbsp;GetQualityColor(EquipmentQuality&amp;nbsp;quality)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;switch&amp;nbsp;(quality)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EquipmentQuality.Common:&amp;nbsp;return&amp;nbsp;Color.gray;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EquipmentQuality.Uncommon:&amp;nbsp;return&amp;nbsp;Color.green;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EquipmentQuality.Rare:&amp;nbsp;return&amp;nbsp;Color.blue;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EquipmentQuality.Epic:&amp;nbsp;return&amp;nbsp;new&amp;nbsp;Color(0.9f,&amp;nbsp;0f,&amp;nbsp;0.9f);&amp;nbsp;//&amp;nbsp;紫色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case&amp;nbsp;EquipmentQuality.Legendary:&amp;nbsp;return&amp;nbsp;new&amp;nbsp;Color(1f,&amp;nbsp;0.8f,&amp;nbsp;0f);&amp;nbsp;//&amp;nbsp;橙色
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;default:&amp;nbsp;return&amp;nbsp;Color.white;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;四、装备与战斗系统的交互&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;装备系统需要与战斗系统紧密集成，实现攻击防御计算和耐久度消耗：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;l607u0j&quot; data-popupid=&quot;l607u0j&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;vgueipm&quot; data-popupid=&quot;vgueipm&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;s5zbwd4&quot; data-popupid=&quot;s5zbwd4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;3v2brfc&quot; data-popupid=&quot;3v2brfc&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;ch2xq35&quot; data-popupid=&quot;ch2xq35&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;CombatSystem&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;攻击目标
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;Attack(GameObject&amp;nbsp;target)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗武器耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.ConsumeWeaponDurability();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算攻击力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;attackPower&amp;nbsp;=&amp;nbsp;EquipmentManager.Instance.CalculateCurrentAttack();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用伤害（简化示例）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;var&amp;nbsp;enemyHealth&amp;nbsp;=&amp;nbsp;target.GetComponent&amp;lt;EnemyHealth&amp;gt;();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(enemyHealth&amp;nbsp;!=&amp;nbsp;null)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;enemyHealth.TakeDamage(attackPower);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;受到攻击
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;void&amp;nbsp;TakeDamage(int&amp;nbsp;damage)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗防具耐久度
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.ConsumeArmorDurability();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算防御力
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;defense&amp;nbsp;=&amp;nbsp;EquipmentManager.Instance.CalculateTotalDefense();

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;计算最终伤害
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int&amp;nbsp;finalDamage&amp;nbsp;=&amp;nbsp;Mathf.Max(1,&amp;nbsp;damage&amp;nbsp;-&amp;nbsp;defense);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;应用伤害到自身
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;GetComponent&amp;lt;PlayerHealth&amp;gt;().TakeDamage(finalDamage);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;五、系统扩展与优化&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 装备强化系统&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;扩展装备系统，实现强化功能：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;tnx5z8y&quot; data-popupid=&quot;tnx5z8y&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;2ejd4bx&quot; data-popupid=&quot;2ejd4bx&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fpay8le&quot; data-popupid=&quot;fpay8le&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;z8w8lw8&quot; data-popupid=&quot;z8w8lw8&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;9x8bfzq&quot; data-popupid=&quot;9x8bfzq&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;EquipmentEnhancement&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;强化装备
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&amp;nbsp;bool&amp;nbsp;EnhanceEquipment(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;ItemData&amp;nbsp;material)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查材料是否足够
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(!HasEnoughMaterials(equipment,&amp;nbsp;material))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;false;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗材料
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ConsumeMaterials(equipment,&amp;nbsp;material);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;提升装备等级
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.level++;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;降低耐久度消耗（强化效果）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.durabilityLossMultiplier&amp;nbsp;=&amp;nbsp;Mathf.Max(0.5f,&amp;nbsp;equipment.durabilityLossMultiplier&amp;nbsp;-&amp;nbsp;0.05f);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;触发更新事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.OnDurabilityChanged?.Invoke(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查材料是否足够
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;bool&amp;nbsp;HasEnoughMaterials(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;ItemData&amp;nbsp;material)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实现材料检查逻辑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&amp;nbsp;true;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;消耗材料
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ConsumeMaterials(EquipmentInstance&amp;nbsp;equipment,&amp;nbsp;ItemData&amp;nbsp;material)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;实现材料消耗逻辑
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 装备耐久度预警系统&lt;/h3&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;当装备耐久度低时给予玩家提示：&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;code-block-element-R6c8c0 light custom-code-block-container--csharp hide-indicator disable-theme-style custom-code-block-container&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 8px 0px 0px; padding: 0px; display: flex; flex-direction: column; position: relative; --chat-md-codeblock-bg-color: #f9fafb; --chat-md-codeblock-header-bg-color: #f3f4f6; --code-area-radius: 6px; --code-area-radius-inner: calc(6px - 1px); --code-area-bg-color: #f9fafb; --code-header-bg-color: #f3f4f6; --code-mask-bg-color: linear-gradient(180deg,rgba(249,250,251,0),#f9fafb); --code-header-icon-color: rgba(0,0,0,.5); --code-header-text-color: rgba(0,0,0,.85); --code-header-icon-bg-color: rgba(0,0,0,.06); --code-block-code-color: #000000d9; --code-block-std-bg-color: #f3f4f6; --code-block-std-err-color: #d60000; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;div class=&quot;code-area-yxsM36 code-area&quot; dir=&quot;ltr&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(249, 250, 251); border-radius: 6px; display: flex; flex-direction: column; height: fit-content; width: 793.026px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;header-wrapper-Mbk8s6&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; background-color: rgb(255, 255, 255); position: sticky; top: 0px;&quot;&gt;&lt;div class=&quot;header-IAeXdE&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0.909091px 0.909091px 0px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: none 100% / 1 / 0 stretch; margin: 0px; padding: 6px 9px 6px 6px; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(243, 244, 246); display: flex; flex-direction: row; flex-shrink: 0; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; height: 32px; justify-content: space-between; border-radius: 5px 5px 0px 0px; overflow-anchor: auto;&quot;&gt;&lt;div class=&quot;title-TXcgFG clickable-cKrA4B&quot; tabindex=&quot;0&quot; aria-describedby=&quot;iv4vi96&quot; data-popupid=&quot;iv4vi96&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px 4px 0px 10px; overflow-anchor: auto; align-items: center; border-radius: 4px; color: rgba(0, 0, 0, 0.5); display: flex; flex-direction: row; gap: 3px; cursor: pointer;&quot;&gt;&lt;div class=&quot;text-OkYU_0&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.85); display: flex; font-family: &amp;quot;PingFang SC&amp;quot;; font-size: 14px; gap: 3px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; text-wrap-mode: nowrap;&quot;&gt;csharp&lt;/div&gt;&lt;div class=&quot;icon-UKNQeW&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 15px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-12&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M21.707 17.293a1 1 0 0 1-1.414 0L12 9l-8.293 8.293a1 1 0 0 1-1.414-1.414l8.293-8.293a2 2 0 0 1 2.828 0l8.293 8.293a1 1 0 0 1 0 1.414&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;action-ysQCxz&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; align-items: center; color: rgba(0, 0, 0, 0.5); cursor: pointer; display: flex; flex-direction: row; gap: 8px; justify-content: space-between;&quot;&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: fit-content; overflow-anchor: auto; padding-inline: 3px;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14 mr-4&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px 4px 0px 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M12 23c6.075 0 11-4.925 11-11S18.075 1 12 1 1 5.925 1 12s4.925 11 11 11m0-20a9 9 0 1 1 0 18 9 9 0 0 1 0-18m-.909 4.667a1 1 0 0 0-1.591.806v7.054a1 1 0 0 0 1.591.806l4.81-3.527a1 1 0 0 0 0-1.612z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;运行&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; data-testid=&quot;code-block-copy&quot; tabindex=&quot;0&quot; aria-describedby=&quot;b0qi830&quot; data-popupid=&quot;b0qi830&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M21 3.5V17a2 2 0 0 1-2 2h-2v-2h2V3.5H9v2h5.857c1.184 0 2.143.895 2.143 2v13c0 1.105-.96 2-2.143 2H5.143C3.959 22.5 3 21.605 3 20.5v-13c0-1.105.96-2 2.143-2H7v-2a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2m-6.143 4H5.143v13h9.714z&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;xwru4uu&quot; data-popupid=&quot;xwru4uu&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4 4a1 1 0 0 1 1 1v3a3 3 0 0 0 3 3h11.086l-5.293-5.293a1 1 0 0 1 1.414-1.414l7 7a1 1 0 0 1 0 1.414l-7 7a1 1 0 0 1-1.414-1.414L19.086 13H8a5 5 0 0 1-5-5V5a1 1 0 0 1 1-1&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;fslmli7&quot; data-popupid=&quot;fslmli7&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; fill-rule=&quot;evenodd&quot; d=&quot;M4.797 16.856a8.28 8.28 0 0 0 6.27 2.87h.008A8.28 8.28 0 0 0 14.372 3.84a11.6 11.6 0 0 1-1.658 7.714 11.62 11.62 0 0 1-7.917 5.303M13.415 1.43a10.28 10.28 0 0 1-2.348 20.296 10.28 10.28 0 0 1-8.883-5.103c-.397-.74.155-1.605.912-1.609a9.617 9.617 0 0 0 9.011-12.258 1.093 1.093 0 0 1 1.308-1.326&quot; clip-rule=&quot;evenodd&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;hoverable-kRHiX2&quot; tabindex=&quot;0&quot; aria-describedby=&quot;l1jm84r&quot; data-popupid=&quot;l1jm84r&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; align-items: center; display: flex; height: 20px; justify-content: center; position: relative; width: 20px; overflow-anchor: auto;&quot;&gt;&lt;span role=&quot;img&quot; class=&quot;semi-icon semi-icon-default text-14&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: ; border: 0px solid; margin: 0px; padding: 0px; display: inline-block; line-height: 0; text-align: center; text-rendering: optimizelegibility; fill: currentcolor; font-size: 14px; overflow-anchor: auto;&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1em&quot; height=&quot;1em&quot; fill=&quot;none&quot; viewbox=&quot;0 0 24 24&quot;&gt;&lt;path fill=&quot;currentColor&quot; d=&quot;M22 3v7a1 1 0 1 1-2 0V4h-6a1 1 0 1 1 0-2h7a1 1 0 0 1 1 1M11.005 21a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-7a1 1 0 0 1 2.002 0v6h6.003a1 1 0 0 1 1 1&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-y8qlFa code-content light-scrollbar-FFk5j5&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border-width: 0px 1px 1px; border-style: solid; border-color: rgba(0, 0, 0, 0.08); border-image: initial; margin: 0px; padding: 12px 16px 16px; background-image: none; background-position: 0% 0%; background-size: auto; background-repeat: repeat; background-attachment: scroll; background-origin: padding-box; background-clip: border-box; flex-shrink: 0; height: fit-content; overflow: overlay; overflow-anchor: auto; border-radius: 0px 0px 5px 5px;&quot;&gt;&lt;pre class=&quot;container-S2LAkl language-csharp&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-top: 0px; margin-bottom: 0px; padding: 0px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; overflow-wrap: normal; font-feature-settings: normal; font-size: 1em; font-variation-settings: normal; --code-text_v3: #000000d9; --code-doc_v3: #00000073; --code-Link_v3: #2f74ff; --code-number_v3: #e54595; --code-keycontrol_v3: #9952e1; --code-function_v3: #ff5d4d; --code-variable_v3: #000000d9; --code-parameter_v3: #4da621; --code-attributes_v3: #c70; --code-selection-bg-color: #a9d6ff; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); word-break: normal; word-spacing: normal; hyphens: none; line-height: 1.5; tab-size: 4; overflow: auto; border-radius: 6px; overflow-anchor: auto; width: fit-content;&quot;&gt;public&amp;nbsp;class&amp;nbsp;DurabilityWarningSystem&amp;nbsp;:&amp;nbsp;MonoBehaviour{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;float&amp;nbsp;warningThreshold&amp;nbsp;=&amp;nbsp;0.2f;&amp;nbsp;//&amp;nbsp;警告阈值（20%）
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;GameObject&amp;nbsp;warningPanel;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[SerializeField]&amp;nbsp;private&amp;nbsp;TextMeshProUGUI&amp;nbsp;warningText;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;Start()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;监听耐久度变化事件
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EquipmentManager.Instance.OnDurabilityChanged&amp;nbsp;+=&amp;nbsp;CheckDurabilityWarning;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;warningPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;检查耐久度警告
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;CheckDurabilityWarning(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;如果是已装备的装备且耐久度低于阈值
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if&amp;nbsp;(equipment.isEquipped&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;!equipment.data.isPermanent&amp;nbsp;&amp;amp;&amp;amp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;equipment.GetDurabilityPercentage()&amp;nbsp;&amp;lt;=&amp;nbsp;warningThreshold)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ShowWarning(equipment);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;显示警告
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;ShowWarning(EquipmentInstance&amp;nbsp;equipment)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;warningText.text&amp;nbsp;=&amp;nbsp;$&amp;quot;{equipment.data.equipmentName}&amp;nbsp;耐久度低，需要修复！&amp;quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;warningPanel.SetActive(true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;3秒后自动隐藏
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Invoke(nameof(HideWarning),&amp;nbsp;3f);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;隐藏警告
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private&amp;nbsp;void&amp;nbsp;HideWarning()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;warningPanel.SetActive(false);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}}&lt;/pre&gt;&lt;/div&gt;&lt;div class=&quot;mask-wrapper-ujeSdZ&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; overflow-anchor: auto; opacity: 0; transition: opacity 0.15s;&quot;&gt;&lt;div class=&quot;mask-lrkkzM&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; background: linear-gradient(rgba(249, 250, 251, 0), rgb(249, 250, 251)) 0% 0% / auto repeat scroll padding-box border-box rgba(0, 0, 0, 0); bottom: 0px; height: 56px; left: -1px; pointer-events: none; position: absolute; width: calc(100% + 2px); overflow-anchor: auto;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;六、平衡设计与优化建议&lt;/h2&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255); margin-top: 20px !important;&quot;&gt;1. 数值平衡要点&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;不同品质装备的耐久度应有明显差异（传说 &amp;gt; 史诗 &amp;gt; 稀有）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;武器耐久度消耗应与攻击力正相关（高攻击力武器消耗更快）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;防具耐久度消耗应与防御力正相关&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;修复成本应与装备品质和当前耐久度挂钩&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;确保装备损坏不会导致游戏无法进行（保留基础能力）&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;2. 性能优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;装备模型使用 LOD 系统，降低远处渲染成本&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;耐久度更新事件只在实际变化时触发，避免频繁更新&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;大量装备展示时使用对象池复用 UI 元素&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备属性计算缓存结果，而非每次需要时重新计算&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 12px 0px 0px; padding: 0px; font-size: 16px; line-height: 24px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;3. 玩家体验优化&lt;/h3&gt;&lt;ul class=&quot;auto-hide-last-sibling-br list-paddingleft-2&quot; style=&quot;list-style-type: none;&quot;&gt;&lt;li&gt;&lt;p&gt;装备耐久度低时提供明显的视觉提示（如闪烁、颜色变化）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;允许玩家一键修复所有装备&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;装备损坏时保留外观但添加损坏特效&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;提供 &amp;quot;自动修复&amp;quot; 选项（消耗资源）&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;重要战斗前提醒玩家检查装备状态&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;header-iWP5WJ auto-hide-last-sibling-br&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 13.5px 0px 0px; padding: 0px; font-size: 18px; line-height: 27px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;七、结语&lt;/h2&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;本文实现的装备系统包含了完整的装备管理和耐久度机制，通过灵活的数据结构设计和事件驱动的架构，确保了系统的可扩展性和可维护性。这个系统不仅能满足基础的装备穿戴需求，还通过耐久度机制增加了游戏的策略性和资源管理深度。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;在实际开发中，可以根据游戏类型和目标玩家群体调整系统复杂度。例如，生存游戏可以强化耐久度管理和修复成本，而休闲游戏可以简化耐久度机制甚至完全移除。关键是让装备系统与游戏的整体玩法和节奏相匹配。&lt;/div&gt;&lt;div class=&quot;container-Uxvbjy md-box-line-break wrapper-GYqxgQ undefined&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 20px 0px 0px; padding: 0px; user-select: none; visibility: hidden; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;&lt;/div&gt;&lt;div class=&quot;auto-hide-last-sibling-br paragraph-pP9ZLC paragraph-element br-paragraph-space&quot; style=&quot;outline: none; -webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); border: 0px solid; margin: 0px; padding: 0px; line-height: 24px; font-size: 16px; overflow-anchor: auto; font-family: Inter, -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; text-wrap-mode: wrap; background-color: rgb(255, 255, 255);&quot;&gt;希望这个装备系统方案能为你的 Unity 项目提供有价值的参考，祝开发顺利！&lt;/div&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 27 Nov 2025 18:02:13 +0800</pubDate></item></channel></rss>