<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. עӼgWcо
        ǰλãƬC̳̾W >> MCUOӋ >> g[

        C++ăȴgsizeof

        :ƽ   Դ:վԭ   c:  •rg20140313   w С

            CZдPڽYwĴ惦gСDZ^Ԓ}漰ӋCĻԭϵyJ錦RCZ׌ܶW߶ò͸Ć}؄eڿƽ_rR@N}ӵďs׃ÿһNϵyԼصČRʽWindowsнԽYw͵Ĵ惦Ԫֹ錦RĻLinuxеČR4ֹR
         
            ôC++еăȴgСЩĆ}
            J錦R϶ҲеĆ}֮һRҪǞ˼ӿxȡٶ
            PڌR@JѽDzϵyȶõȻLinuxcWindowsڲeôC++PڌR϶ҲһIJePڌRJֻҪӛסƽrʹõϵyČRʄtͿWindowsнԽYw͵Ĵ惦Ԫֹ錦RĻLinuxеČR4ֹR
          
            J͑ԓӑՓڻЩɆTռд惦gЩɆTռÃȴg
            C++ռ惦^gҪǷstaticĔҪNõĔеĺ•ԼxȴgҪעеvirtual̓һ΃ȴ^һf4ֹʲôֻǰstaticstaticκһČǾwijһČȴ^ֻһȴ^惦staticҲе@Բwijһ͵ăȴg
            ˿JĴ惦gС飺
            staticɆTĴС + 4 ֹ̓Ĵ惦g
            Ȼ@СДɆTСįBǴһR}wđԓPČR

         
            J϶ҪPһĴ惦g
            C++^һ^õ^ʹøNڻĻAϔUչ@rа˻Ϣһڻд̓r^˻̓ѽ^̓^в̓Ĵ惦gе̓һKȴ^HHҪ]MķstaticɆTăȴgС
            ˿JĴ惦gС飺
            惦g + еķstaticɆTĴ惦g
         
           ߀һDZ^r̓^еr@rĴ惦gС͕l׃
            Ĵ惦g + еķstaticɆTĴ惦g + ÿһ̓惦g
          
            ҲһЩfĆ}
            RĆ}

            class test
            {
            public:
                    test();
            private:
                    int a;
                    char c;
            };

            cout << sizeof(test) << endl;

          ĴalinuxԼwindows¶ݔ8ݔ5@CZѽӑՓ^Ԓ}fRC++ҲҪ]PڲϵyIJںһyһf
            ̓}
            ӑՓ̓҂testһ̓ȻٜyԇY  

            class test
            {
            public
                    test();
                    virtual ~test();
            private:
                    int a;
                    char c;
            };
            cout << sizeof(test) << endl;

        @δacǰĴa]ʲô^eֻһ̓Ȼg{ԇ@rݔĽY12Ҳfһ̓ԺĔɆT4ֹôǷÿһ̓ռ4ֹ䌍Dztestмһµ̓virtual void get_a_c(),@rݔĽY߀12@fе̓4ֹ
            static
            ҂֪staticǷnjČČijһ͵Ĵ惦gxֻ•ʼֻȻ@ҲwĴ
            Ĵ惦g
            Ļ^˺ܶɆTԼҲӺܶijɆT̓Ҳ^Ծв@ʽx̓ҲڏĻ^̓̓Ҫ~ӋȴgֻҪӻķstaticɆTСxʾԓݔ20ӵķstaticdouble dĴ惦gСCķ

            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:
                    double d ;
            };

            cout << sizeof(derived_test) << endl;

        yԇ̓^еĴ

            class A
            {
                    char i[3];
            public:
                    virtual void a(){};
            };

            class B : public virtual A
            {
                    char j[3];
            public:
                    virtual void b(){}
            };

            class C: public virtual B
            {
                    char k[3];
            public:
                    virtual void c(){}
            };

            int main()
            {
                cout << "sizeof(A): " << sizeof(A) << endl;
                cout << "sizeof(B): " << sizeof(B) << endl;
                cout << "sizeof(C): " << sizeof(C) << endl;
                return 0;
            }

        һ^Cϵfһ²ϵyԼNCϵӰ푷

            #include <iostream>
            #include <string>
            #include <vector>

            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:
                double d ;
            };

            class base
            {
            private:
                char a;
                static int refrence_count;
                std::string name;
                double price;
                std::vector<double> 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<double> 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:
                double discount;
                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_base is " << 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;
            }

        windowslinuxĽYքe£
        windows

        Linux

        ĽY֪֮ڃɂϵyYDzһӵfϵyҲĴ惦gС^Ӱ

        P]

        P

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮