C++ virtual + protected?
- by user346113
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