C++ virtual + protected?

Posted by user346113 on Stack Overflow See other posts from Stack Overflow or by user346113
Published on 2010-12-30T12:43:15Z Indexed on 2010/12/30 12:53 UTC
Read the original article Hit count: 151

Filed under:
|
|
|

Hi,

In C++, I have a base class A, a sub class B. Both have the virtual method Visit. I would like to redefine 'Visit' in B, but B need to access the 'Visit' function of each A (and all subclass to).

I have something like that, but it tell me that B cannot access the protected member of A! But B is a A too :-P

So, what can I do?

class A
{
protected:
virtual Visit(...);
}

class B : public class A
{
protected:
vector<A*> childs;
Visit(...);
}

B::Visit(...)
{
 foreach(A* a in childs)
 {
   a->Visit(...);
 }
}

Thx

© Stack Overflow or respective owner

Related posts about c++

Related posts about class