0

How do I access the base class protected/public methods in a derived object ? For example A and B are as defined below...

class A {
  int a;
  protected:
    int set(int v){ a = v; };
  public:
    A(){};
    int foo(){ return 0;};
};

class B : A {
   int b;
   public:
    B(){};
};

int main(int a, char *argv[])
{
  B *b = new B();
  b->set(3); // I cannot access this method?
  return 0;
}
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by tazboy
0

Of course, you can't access protected method in main! Only member functions of derived classes can access protected members.
Re-read your C++ textbook...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.