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;
}

Recommended Answers

All 2 Replies

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...

Ouch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.