1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      C++語言學(xué)習(xí)(五)——C++語言中的CV限定符錯(cuò)誤-創(chuàng)新互聯(lián)

      C++語言學(xué)習(xí)(五)——C++語言中的CV限定符錯(cuò)誤

      ?一、CV限定符錯(cuò)誤簡介

      1、CV限定符簡介

      CV限定符即cv-qualifier,C++語言中指const和volatile限定符。
      通常,C++語言中有兩種情況不能使用CV限定符進(jìn)行限定:
      A、非成員函數(shù)不能使用CV限定
      B、靜態(tài)成員函數(shù)不能使用CV限定

      成都創(chuàng)新互聯(lián)10多年成都定制網(wǎng)頁設(shè)計(jì)服務(wù);為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及高端網(wǎng)站定制服務(wù),成都定制網(wǎng)頁設(shè)計(jì)及推廣,對成都服務(wù)器租用等多個(gè)方面擁有多年的網(wǎng)站制作經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。

      2、CV限定符錯(cuò)誤信息簡介

      C++語言中CV限定符錯(cuò)誤信息如“cannot have cv-qualifier”,常見的CV限定符錯(cuò)誤信息如下:
      A、非成員函數(shù)的CV限定符錯(cuò)誤信息
      error: non-member function 'xxxxxxxxx' cannot have cv-qualifier
      B、靜態(tài)成員函數(shù)的CV限定符錯(cuò)誤信息
      error: static member function 'static xxxxxxx' cannot have cv-qualifier

      二、C++語言的CV限定場合

      1、非成員函數(shù)

      在C++中,非成員函數(shù)不能含有CV限定,即const和volatile限定。

      #include 
      
      using namespace std;
      
      double sum(double a, double b)const
      {
          return a + b;
      }
      //error: non-member function 'double sum(double, double)' cannot have cv-qualifier
      
      int main(int argc, char *argv[])
      {
          double a = 3.14;
          double b = 2.0;
          double ret = sum(a, b);
          return 0;
      }

      上述代碼報(bào)錯(cuò),非成員函數(shù)sum不能使用const進(jìn)行限定。

      #include 
      
      using namespace std;
      
      double sum(double a, double b)volatile
      {
          return a + b;
      }
      //error: non-member function 'double sum(double, double)' cannot have cv-qualifier
      
      int main(int argc, char *argv[])
      {
          double a = 3.14;
          double b = 2.0;
          double ret = sum(a, b);
          return 0;
      }

      上述代碼報(bào)錯(cuò),非成員函數(shù)sum不能使用volatile進(jìn)行限定。
      非成員函數(shù)不能使用const和volatile對函數(shù)進(jìn)行限制,但在函數(shù)中或函數(shù)的返回值可以使用const和volatile進(jìn)行限定。

      #include 
      
      using namespace std;
      
      volatile double sum(double a, double b)
      {
          volatile double c = a + b;
          return c;
      }
      
      int main(int argc, char *argv[])
      {
          double a = 3.14;
          double b = 2.0;
          double ret = sum(a, b);
          return 0;
      }

      類的友元函數(shù)不是類的成員函數(shù),不能使用const和volatile對友元函數(shù)進(jìn)行限制。

      #include 
      
      using namespace std;
      
      class Test
      {
      private:
          static int data;
      public:
          Test()
          {
              data++;
          }
          //靜態(tài)成員函數(shù)
          static int count()
          {
              return data;
          }
          friend int getValue()const;//error
          //error: non-member function 'int getValue()' cannot have cv-qualifier
          ~Test()
          {
              data--;
          }
      };
      
      int Test::data = 0;
      //error: non-member function 'int getValue()' cannot have cv-qualifier
      int getValue()const//error
      {
          return Test::data;
      }
      
      int main(int argc, char *argv[])
      {
          cout << Test::count() << endl;
          Test test;
          cout << test.count() << endl;
          return 0;
      }

      上述代碼報(bào)錯(cuò),類的友元函數(shù)getValue不能使用const和volatile進(jìn)行限定。

      2、靜態(tài)成員函數(shù)

      在C++中,靜態(tài)成員函數(shù)不能有CV限定,即const和volatile限定。

      #include 
      
      using namespace std;
      
      class Test
      {
      private:
          static int data;
      public:
          Test()
          {
              data++;
          }
          //靜態(tài)成員函數(shù)
          static int count()const
          {
              return data;
          }
          //error: static member function 'static int Test::count()' cannot have cv-qualifier
          ~Test()
          {
              data--;
          }
      };
      int Test::data = 0;
      
      int main(int argc, char *argv[])
      {
          cout << Test::count() << endl;
          Test test;
          cout << test.count() << endl;
          return 0;
      }

      上述代碼報(bào)錯(cuò),類的靜態(tài)成員函數(shù)count不能使用const關(guān)鍵詞進(jìn)行限定。

      #include 
      
      using namespace std;
      
      class Test
      {
      private:
          static int data;
      public:
          Test()
          {
              data++;
          }
          //靜態(tài)成員函數(shù)
          static int count()volatile
          {
              return data;
          }
          //error: static member function 'static int Test::count()' cannot have cv-qualifier
          ~Test()
          {
              data--;
          }
      };
      int Test::data = 0;
      
      int main(int argc, char *argv[])
      {
          cout << Test::count() << endl;
          Test test;
          cout << test.count() << endl;
          return 0;
      }

      上述代碼報(bào)錯(cuò),類的靜態(tài)成員函數(shù)count不能使用volatile關(guān)鍵詞進(jìn)行限定。

      另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


      網(wǎng)站標(biāo)題:C++語言學(xué)習(xí)(五)——C++語言中的CV限定符錯(cuò)誤-創(chuàng)新互聯(lián)
      鏈接分享:http://ef60e0e.cn/article/dgihde.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        平舆县| 龙泉市| 桃江县| 新密市| 阜城县| 双桥区| 平定县| 巴南区| 灌南县| 东阳市| 彰化市| 黑河市| 贵溪市| 行唐县| 佛学| 宝应县| 金秀| 霍邱县| 元朗区| 通山县| 开江县| 东港市| 大洼县| 长丰县| 四子王旗| 惠安县| 弥渡县| 平塘县| 齐河县| 邹平县| 涟源市| 万安县| 佛坪县| 宣威市| 扶余县| 额济纳旗| 凉城县| 南昌市| 罗江县| 子洲县| 崇礼县|