The following is a half summary half rant about the C++ I was able to pick up in a day. I have a background with C, Java and Ruby, so a lot of it was familiar already, but the syntax, idioms, and some of the language features are still quite different. My aim was to pick up enough to understand how to do constraint programming with Gecode, though I think I went a little beyond that.
I started at Google’s code school, but wouldn’t recommend it unless you have no idea what you are doing & a lot of time to spend on it. See footnote. I found http://www.cplusplus.com/doc/tutorial and http://www.cprogramming.com/tutorial helpful. This article on C++ from Java could be interesting, but I’m going to skip it and get on with the Gecode homework assignments now.
The first half of the tutorials I’ve seen are essentially C tutorials, and can be skipped if you’re comfortable with control statements and basic pointers.
Control structures
The same as C.
Objects
There are some confused tutorial writers out there who think “class” and “object” are synonyms, but never mind that for now.
Class definitions look a lot like Java, but with some important differences.
Member function (method) definitions can be declared in the class body, but declared somewhere else. I like this idea a lot, due to it providing a clean interface, but have no idea how well it scales.
Object instantiation is a lot more concise than in Java (no assignment needed!), but be aware of the difference between object holding variables, and pointers to objects. Also check up on polymorphism with pointers, and virtual functions, and seeing how virtual funcs are in other languages. I prefer how Java and Ruby abstract this.
The relationship between classes and structs (unions) is interesting, coming from languages where objects are something special.
Emphasis seems to be put on memory locations rather than object notions such as encapsulation. I’m sure there are other talks/tutorials which improve on this (perhaps here) but I found this interesting.
Having seen how inheritence works (or doesn’t, if you look at friendship) it may be confusing to see constructors inheriting from things that aren’t class names. Actually “:” has been overloaded and you should take a look at initializer lists. This confused me a lot, and is what pushed me into spending yesterday on this.
Being able to specify public/protected/private for the inherited classes, and also having direct multiple inheritance, are interesting aspects of the language, though - as usual - this can be achieved through other patterns such as composition.
Templates
Are Java generics, for example List<Int> and List<String>
STL
This was disappointing, I thought from what I’d heard in the past it was some kind of macro system. Instead it’s the C++ equivalent of the Java standard library. It provides things like List, Vector, etc. Tutorial. Of course, coming from Java and other languages with reasonable standard libraries this isn’t a big deal, but I am forgetting that C came with nothing and you had to write, find, or buy everything for yourself.
Memory management
Godspeed.
Footnote, on teaching C++ to beginners
The Google code school for C++ provides some well-meaning practical examples, sets the activity in context by explaining some things they do at Google, and giving examples of other interesting software, but largely the tuition is delegated to outside tutorials. Those tutorials are incomplete and not so hot.
To be fair to the authors though, writing a beginner’s guide to C++ is a futile endeavour: C++ is a terrible language for beginners. There are too many concepts to cram into a small space. When you’re teaching a concept, avoid detours. If you can do a 1-line hello world that’s great. If you have to explain stdio, compilation, linking, platforms to get there you’ve already lost. I remember some years ago being very confused by stdio and how it related to my program. If you are writing in Ruby or some other higher level language you just don’t need to see these things, they’re abstracted away. Don’t try and teach systems concepts and object concepts and procedural programming concepts and algorithms (etc) to someone — especially me — all at once!
I wish I’d picked up PHP, Python, or even Lisp instead of buying C++ books when I was younger. Alas, I wanted to work on Quake mods. Never got past chapter 3/4/5 on structs/pointers/malloc. Now, some years on, having used other languages to build things, learn object concepts, pick up system concepts through shell usage etc, it all fits together and seems trivially simple. Back then, it was overwhelming. :)
Now may the search-space pruning commence!