<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # C++ 中的抽象 > 原文: [https://beginnersbook.com/2017/09/abstraction-in-c-with-example/](https://beginnersbook.com/2017/09/abstraction-in-c-with-example/) 抽象是[面向對象編程](https://beginnersbook.com/2017/08/cpp-oops-concepts/)的功能之一,您只需向用戶顯示相關詳細信息并隱藏不相關的詳細信息。例如,當您向某人發送電子郵件時,您只需單擊“發送”即可獲得成功消息,單擊“發送”時實際發生的情況,數據通過網絡傳輸給收件人的方式對您來說是隱藏的(因為它與您無關) 。 讓我們看看如何使用訪問說明符在 C++ 程序中實現: ## 抽象示例 ```cpp #include <iostream> using namespace std; class AbstractionExample{ private: /* By making these data members private, I have * hidden them from outside world. * These data members are not accessible outside * the class. The only way to set and get their * values is through the public functions. */ int num; ? ?char ch; public: void setMyValues(int n, char c) { num = n; ch = c; } void getMyValues() { cout<<"Numbers is: "<<num<< endl; cout<<"Char is: "<<ch<<endl; } }; int main(){ AbstractionExample obj; obj.setMyValues(100, 'X'); obj.getMyValues(); return 0; } ``` **輸出:** ```cpp Numbers is: 100 Char is: X ``` ## 數據抽象的優勢 使用此功能的主要優點是,當代碼發展并且您需要在代碼中進行一些調整時,您只需要修改已將成員聲明為私有的高級類。由于沒有類直接訪問這些數據成員,因此您無需更改低級別(用戶級別)類代碼。 想象一下,如果您將這些數據成員公開,如果在某些時候您想要更改代碼,則必須對直接訪問成員的所有類進行必要的調整。 **數據抽象的其他優點是:** 1)通過使數據私有化并避免可能破壞數據的用戶級錯誤,使應用安全。 2)這避免了代碼重復并增加了代碼的可重用性。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看