Problem in accessing the protected datamember

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rag84dec
    New Member
    • Mar 2007
    • 100

    Problem in accessing the protected datamember

    Hi,
    I have a protected vector declared in a header file abc.h
    Code:
    class A
    {
    protected: typedef vector<int> y;
    y vecInstance;
    void useProtected(void);
    }
    To access the protected vecInstance i declared useProtected() in the same classs as above
    I used it in another cpp file "a.cpp"
    Code:
    A instanceOfA;
    instanceOfA.useProtected();
    And i finally declared "useProtected() " in one cpp file
    [code]
    void A::useProtected ()
    {
    int i=vecInstance.s ize();
    }
    [/ode]
    but ended up getting error
    Code:
    Protected cannot use protected member


    please help....
    }
  • Darryl
    New Member
    • May 2007
    • 86

    #2
    protected: is not a line item modifier, everything listed after protected: will be protected. You need to add a public: section
    Code:
    class foo
    {
    protected:
    int y;
    int x;
    public:
    int getx();
    int gety();
    }
    both of my member variables are protected, while both of the get functions are public

    Comment

    Working...