1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ask about protected keyword

Discussion in 'C++' started by imported_micheal9000, Sep 9, 2010.

  1. imported_micheal9000

    imported_micheal9000 New Member

    Joined:
    Sep 9, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Please help me. I read many books and they talk: protected member can be accessed from member in same class, friend of own class, derivative class and friend of derivative class. I write code on codeblocks, all things are right, but friend of derivative class is wrong. Why ? Please help me. Here's my code
    ------------------
    Code:
    class Polygon{
        protected:
            int w, h;
        public:
            void setValue(int w, int h){
                this->w = w;
                this->h = h;
            }
    };
    class Rectangle:public Polygon{
        public:
            int area(){
                return w*h;
            }
        friend int area1();
    };
    
    int area1(){
        return w*w;
    }
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    What is "w" here?? w is not recognized..pass the object of Rectangle in area1 and then access "w" ...
     

Share This Page