<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > C++中類的內(nèi)存空間大?。╯izeof)分析

          C++中類的內(nèi)存空間大?。╯izeof)分析

          作者: 時(shí)間:2016-12-01 來源:網(wǎng)絡(luò) 收藏

          #include
          #include
          #include

          class test
          {
          public:
          test();
          virtual ~test();
          virtual void get_a_c();
          private:
          int a;
          char c;
          };

          class derived_test:public test
          {
          public:
          virtual ~derived_test();
          private:
          doubled ;
          };

          class base
          {
          private:
          char a;
          static int refrence_count;
          std::string name;
          double price;
          std::vector dvec;
          public:
          base();
          virtual ~base();
          static int get_count();
          };

          int base::get_count()
          {
          return refrence_count;
          }

          int base::refrence_count = 0;

          class new_base
          {
          private:
          char a;
          double price;
          std::vector dvec;
          std::string name;
          static int refrence_count;
          public:
          new_base();
          virtual ~new_base();
          static int get_count();
          };

          int new_base::get_count()
          {
          return refrence_count;
          }
          int new_base::refrence_count = 0;

          class derived: public base
          {
          private:
          int min_qty;
          double discount;
          static int newp;
          public:
          derived();
          virtual ~derived(){};
          };

          class new_derived:public new_base
          {
          private:
          doublediscount;
          int min_pty;
          static int newp;
          public:
          new_derived();
          virtual ~new_derived(){}
          };

          int main()
          {
          std::cout << "The size of test is " << sizeof(test) << std::endl;
          std::cout << "The size of derived_test is " << sizeof(derived_test) << std::endl;
          std::cout << "The size of base is " << sizeof(base) << std::endl;
          std::cout << "The size of new_baseis " << sizeof(new_base) << std::endl;
          std::cout << "The size of derived is " << sizeof(derived) << std::endl;
          std::cout << "The size of new_derived is " << sizeof(new_derived) << std::endl;

          return 0;
          }

          上面在windows和linux的結(jié)果分別如下:
          windows:

          Linux:

          從上面的結(jié)果可以之知道在兩個(gè)系統(tǒng)下,結(jié)果是不一樣的。說明操作系統(tǒng)也對(duì)類的存儲(chǔ)空間大小有較大的影響。


          上一頁 1 2 下一頁

          關(guān)鍵詞: C++內(nèi)存空間sizeo

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();