C++ for C programmers, part 2 of 2

August 2010

Original article on blog.brush.co.nz

This article lists the features C++ adds to C, from an ex-C programmer’s point of view. A couple of months ago I wrote part 1, which detailed the non-OO features. This second part details the object-oriented features, though I haven’t given them exactly watertight separation.

Again, this is a quick reference, and the idea is to follow the links to further information if you want to know more about any of them.

So, part 2 of 2, the OO features.

Class and (de)constructors

Virtual functions

Inheritance and friends

Type casting

New and delete

Operator overloading

Templates

Exceptions

Well, thanks for listening!

Comments

Andy Morris 10 Aug 2010, 15:15

The point of private inheritance is the same as it is everywhere – it’s an implementation detail. It’s almost the same as just including an instance of the base class as a private member and using it, but there’s the added benefit that you can access the protected members on the base class.

In the situation where you are building object A and your implementation needs to include object B, but you need to access to B’s protected method foo(), you could:

The private inheritance method is probably better in this case.

— Ayjay on Fedang/coding/C++

Ben 10 Aug 2010, 15:25

Thanks, Andy — that explains it pretty well.

Berwyn 3 Aug 2012, 10:27

Stroustrup has moved his faqs to a domain with his own name. I have updated the rotten links to it.