I was looking up some unknown book about C++. and faced with this table which title reads.
" ― As the result of inheritance all fields of base class are being inherited by derived class."
And then it shows such table.
My question is: Are private fields and functions from base class accessible (as noted in the confusing table) by derived class during private inheritance?
I have read ISO C++ standard, and there is no any mentions about private fields and private inheritance combined, though I have tried myself to find out, and the code behaves as it supposed to. Example I used.
#include <iostream>
using namespace std;
class BASE
{
private:
int x;
};
class DERIVED : private BASE
{
public:
void print_X(void){cout << x << "\n";}
};
int main()
{
return 0;
}
Then compiler error message says:
main.cpp:23:36: error: ‘int BASE::x’ is private within this context
23 | void print_X(void){cout << x << "\n";}
So now I wonder, whether I do something wrong, or the publisher of that book should correct that pages?!