You can think of (C++) classes as being their own best “friend”.  

This is to do with inheritance in the C++ programming language.

I’ve read in quite a few places on the internet, that inheritance in C++ is class-based, not object-based. Now I couldn’t understand what that meant, until I actually started reading about classes on the internet.

It turns out the textbook didn’t cover important details like these.

It is perfectly legal for objects of the same class to access each other’s private data. You might think, “Wha… is he talking abou…?” and I must admit I thought the same.

But what I mean to say is that if you declare multiple objects of the same class, then the member functions of those objects can access each other’s members, apart from their own members, including those under the private access specifier.

It gets weirder when inheritance doesn’t use the public visibility mode. In protected inheritance, the derived class’s members cannot access the members of the base class, only the members in the derived class that came there because they were inherited from the base class. It is perfectly possible, though, for the base class to access protected members of the classes derived from it that arrived there because they were inherited from the base class.

These are all peculiar things, and there are small tidbits and hints everywhere in the syntax, which is itself not clear or intuitive enough to make learning this stuff any easier.

But it has to be done, so I’m doing it…

 
5
Kudos
 
5
Kudos

Now read this

The whole is greater than the sum of its parts

There’s a purely Physics explanation for the whole being greater (in Physics, it can also be lesser) than the sum of its parts. But I’m not talking about that meaning, which involves the equation E = mc2, one of the most popular... Continue →