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

Pencil

A very, very versatile tool. Writing is something that only humans can do. And the pencil is the perfect tool to exercise this ability. It’s better than pens because you can erase pencil marks and reuse the same space. Drawing is another... Continue →