I'm working on a project to learn about object oriented programming. From what I understand, when a class is derived from a base class, it can access all of the public member functions of the base class. In C++ a public inheritance means that private members cannot be accessed. So what happens when a private member function is modified in a base class?
I have tried building some test programs to see what happens, but I'm still extremely confused. I also tried looking online to see if I can find any answers, but I didn't really find any.
class Base
{
private:
int length;
public
void increaseLengthByOne();
};
void Base::increaseLengthByOne()
{
this->length++;
}
class Derived : public Base
{
private:
int dLength;
public:
void newFunction();
};
void Derived::newFunction()
{
printf("New function working");
increaseLengthByOne();
}
From what I understand, dLength won't be changed and Length can't be changed. What does the increaseLengthByOne function do then? And how would I make it so the increaseLength function can increase dLength?
couts to verify your assumptions. IsincreaseLengthByOne()really no able to modifylengthwhen called from the derived? - 463035818_is_not_a_number