• <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 丑石 閱讀(708) 評論(0)  編輯 收藏 引用 所屬分類: C++ problem and solution

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲午夜无码AV毛片久久| 国产精品久久久久久久午夜片 | 久久精品一区二区| 久久99精品久久久久久齐齐| 香蕉久久AⅤ一区二区三区| 欧美大香线蕉线伊人久久| 色综合久久精品中文字幕首页| 久久精品国产亚洲欧美| 亚洲а∨天堂久久精品9966| 亚洲精品无码成人片久久| 国产精品99久久久久久猫咪| 麻豆久久久9性大片| 韩国三级大全久久网站| 午夜精品久久久久久久无码| 国产精品久久国产精麻豆99网站| 国内精品九九久久精品| 2021国产精品午夜久久| 亚洲国产成人精品91久久久| 精品国产乱码久久久久久1区2区 | 久久婷婷五月综合97色一本一本 | 久久亚洲中文字幕精品有坂深雪| 狠狠色综合久久久久尤物| 少妇久久久久久被弄高潮| 久久亚洲欧洲国产综合| 欧美一级久久久久久久大| 久久精品无码一区二区无码| 久久香蕉国产线看观看精品yw| 久久久久久亚洲精品不卡| 日日狠狠久久偷偷色综合96蜜桃| 99久久无色码中文字幕| 久久青青草原亚洲av无码app| 久久婷婷五月综合97色直播| 麻豆一区二区99久久久久| 欧美亚洲国产精品久久| 一本色道久久88综合日韩精品| 99久久国产综合精品网成人影院| 久久精品免费网站网| 国产91久久综合| 狠狠精品久久久无码中文字幕 | 亚洲精品99久久久久中文字幕| 久久久久久亚洲精品无码|