News for hackers. Stuff that matters.
Re:Why You Should Know C++ by wheels on Wednesday May 20, 2009 @11:04AM (#618649)
It's not that those features aren't exposed in C++, it's that C++ has different (more modern) mechanisms for doing the same thing.

C++ has templates, so you don't need to do as much with macros. C++ has virtual functions and overloaded operators (allowing for functors), so you don't need to do as much with function pointers. Structures can have methods in C++, so the way that you'd set up an opaque type is quite different in C++.

C++ also has about 10000 other features as well though, which is what makes it unwieldy to learn. The patterns mentioned above aren't about efficiency; they're about encapsulation.

Just to give an example -- in C++ if you want to set up a callback, for example with an observer pattern, you'd use a pure virtual function (and then pass in a concrete instance of that class) or a functor. You can't do that in C, so you use a function pointer. You learn to work with function pointers more because they're a necessary part of designing C APIs, whereas they're not in C++.

(Note that it's the language I'm best at, followed by C, so this isn't random C++ hating.)

There are no comments on this comment yet.