C++ for C programmers, part 2 of 2

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!

10 August 2010 by Ben    5 comments

5 comments and pings (oldest first)

Andy Morris 10 Aug 2010, 15:15 link

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:

  • Privately derive A from B, allowing A’s implementation to call this->foo(), or
  • Create a class C that derives publicly from B, somehow expose C.foo(), then include C in A

The private inheritance method is probably better in this case.

— Ayjay on Fedang/coding/C++

Ben 10 Aug 2010, 15:25 link

Thanks, Andy — that explains it pretty well.

[…] let me know if I’ve missed any non-OO features. The following week’s entry contains the second part describing the object-oriented features C++ has […]

[…] C++ for C programmers, part 2 of 2 — the OO features […]

Berwyn 3 Aug 2012, 10:27 link

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