I am facing a situation where I need to access child member variables inside the parent class. I know this is against OO principles but I have to deal with a scenario where
You can use the curiously recurring template pattern to achieve this.
template
class Parent
{
void DoSomething()
{
// This is what I need
T::childMember = 0;
}
virtual ~Parent() {}
};
class Child1 : Parent
{
int childMember;
friend class Parent;
};