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

            My Links

            Blog Stats

            News

            常用鏈接

            留言簿(1)

            隨筆分類(13)

            隨筆檔案(17)

            文章檔案(1)

            相冊

            收藏夾(1)

            Friends' blog

            useful sites

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            综合久久给合久久狠狠狠97色| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久久久亚洲av毛片大| 久久99精品国产麻豆蜜芽| 欧美色综合久久久久久| 蜜桃麻豆WWW久久囤产精品| 久久亚洲熟女cc98cm| www.久久精品| 日韩精品无码久久一区二区三| 热综合一本伊人久久精品| 亚洲中文字幕无码一久久区| 国产伊人久久| 99久久婷婷免费国产综合精品| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 国产高潮久久免费观看| 蜜臀av性久久久久蜜臀aⅴ | 久久亚洲AV成人无码电影| 久久播电影网| 色综合合久久天天给综看| 精品久久久久久国产牛牛app | 国产午夜福利精品久久2021| 亚洲AV伊人久久青青草原| 久久精品国产72国产精福利| 精品久久777| 久久人人爽人人爽人人片AV麻豆| 无码国内精品久久人妻蜜桃| 久久亚洲精品人成综合网| 色综合久久久久久久久五月| 久久综合噜噜激激的五月天| 国产精品亚洲综合久久| 久久亚洲日韩精品一区二区三区 | 欧美亚洲另类久久综合| 99久久这里只有精品| 99久久国产主播综合精品| 热RE99久久精品国产66热| 亚洲精品午夜国产va久久| 亚洲香蕉网久久综合影视| 日韩精品久久久久久| 久久综合给合综合久久| 久久精品无码专区免费青青 | 狠狠色综合网站久久久久久久高清|