• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            linux&c++ R&D

            programing is a pleasure!

            Permission problem on a derived private method from public method

            problem:
            Is there a good explanation why compilation tags error for the call to
            AA.method(). It is public in the base class. If cast to baseclass,
            then compiler says it's ok.

            class A 


            public
                A() 
            {} 
                virtual 
            ~A() {} 
                virtual 
            void method(void{ std::cout << "A::method" <<std::endl; } 
            }
            ;// A 
            class AA : public A 
            public
                AA() 
            {} 
                virtual 
            ~AA() {} 
            private
                virtual 
            void method(void
                   A::method(); 
                   std::cout 
            << "AA::method" << std::endl; 
                }
             
            }
            ;// A 
            int main() 

                AA obj; 
                A
            * p = &obj; 
                p
            ->method(); 
                
            //((A&)obj).method(); 
                obj.method();                  // ERROR: 
             }


            gcc -o drvd drvd.cpp -lstdc++ -lm
            drvd.cpp: In function `int main()':
            drvd.cpp:26: error: `virtual void AA::method()' is private
            drvd.cpp:46: error: within this context
            http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/7ae23191ff4de6a9/4560e82948e9b91e#4560e82948e9b91e

            solution:
                 Above ,it seems as if it is a paradox !
                 why in devived class,function method() is declared as a private memeber,still in the way
                  A* p = &obj; 
                p
            ->method(); 
               it is right!
              The phenomena is explained in the Inside the C++ object model!
              In fact,p->method() is checked in two phases!
             At complie time,p->method()
             According to p type,check method()'s access level and method()'s validity,such as membership!
            so p->method() is right!
            At run time,
            p->method() is called in polymorphism way according to p's RTTI information!
            extending:
            Although it looks strange,maybe we can employ it!
            for example:
            class A{
            public:
            virtual void method()=0;
            }
            class AA:public A{
            private:
            virtual void method(){
            ...
            }
            };
            Obviously,
            A is interface and AA is a implemention!
            In the way,if you use AA directly,
            it will result in error,so prevent any subclass's use!
            A is the only entry!
            It may be helpful in some library's device!


            posted on 2007-04-21 12:44 丑石 閱讀(707) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲人成精品久久久久| 欧美午夜精品久久久久久浪潮| 亚洲?V乱码久久精品蜜桃| 精品久久久久久国产三级| 久久国产精品免费一区二区三区| 亚洲美日韩Av中文字幕无码久久久妻妇| 日韩一区二区三区视频久久| 97精品依人久久久大香线蕉97| 久久亚洲高清观看| 国产成人精品久久| 国产精品熟女福利久久AV| 77777亚洲午夜久久多人| 国产成人无码精品久久久久免费| 亚洲国产精品成人AV无码久久综合影院| 欧美牲交A欧牲交aⅴ久久| 久久综合综合久久综合| 夜夜亚洲天天久久| 亚洲va中文字幕无码久久| 久久精品无码一区二区app| 久久精品国产亚洲av麻豆色欲| 精品多毛少妇人妻AV免费久久| 一本色道久久综合亚洲精品| 久久五月精品中文字幕| 久久99热精品| 99久久精品日本一区二区免费| 久久天天躁狠狠躁夜夜不卡| 国产2021久久精品| 久久精品国产91久久麻豆自制 | 久久精品国产99国产精品| 日本强好片久久久久久AAA| 中文精品99久久国产| 婷婷久久综合九色综合绿巨人| 久久九九亚洲精品| 99热成人精品免费久久| 久久久久久久亚洲Av无码| 久久亚洲国产成人精品性色| 中文字幕无码免费久久| 无码专区久久综合久中文字幕| 久久综合亚洲欧美成人| 久久精品a亚洲国产v高清不卡| 久久婷婷五月综合97色一本一本 |