I've wanted to learn C++ for awhile and took AP Computer Programming in High School (back when it was C++ and not Java). I enjoy C and just haven't found the time to learn C++ or I'll just fall back on C# where I'm much more productive.

My question is this: given that C++ '11 has been approved (although I know not fully implemented) does this change the way I should approach learning C++? I own C++: The Complete Reference By Herb Schildt which is from 1998. Does the newly approved standard make learning from such books less important than some of the newer tutorials/books that include things from the standard? Is there any benefit from learning from the older books?

  • 9
    Oof. Schildt. I can't speak to the quality of his C++ materials, but his C materials were sub-standard for a long time (even the latest edition of C:TCR still has a few non-trivial errors). I'd recommend looking for a more current work by a different author. – John Bode Aug 16 '11 at 13:59
  • C++ 11 didn't change the basics of C++ which must be learned in order to do anything that was introduced in the lastest revision and does not exist in a previous version of C++. – Ramhound Aug 16 '11 at 14:01
  • 11
    Never trust a book by Herb Schildt. Really, while the majority of C++ books out there are bad books (and I am not referring to stylistic issues here, but blatant factual errors and promoting programming styles well-known to lead to buggy code), Schildt's books have been so outstandingly bad, his name became somewhat of a meme. – sbi Aug 16 '11 at 14:18
  • 4
    @Ramhound: I disagree. If that was true, we'd still all learn manual resource management first, and only then safer ways to do dynamic resources. Thankfully, this is (slowly) changing. New possibilities, even if they are "only" in the library, call for new idioms. If you start with a language, why learn older idioms first, only to have to unlearn them later? – sbi Aug 16 '11 at 14:21

Absolutely. These days three things that are usually in lesson 2 should move much, much later:

  • strings as arrays of char*, the strlen, strxxx methods, and so on
  • arrays in general and pointer arithmetic
  • delete what you new, delete[] what you new[], and even destructors

These things that are usually in lesson 99 should move much, much earlier

  • templates as things to use (write, not so much)
  • std::string
  • std::shared_ptr<>
  • std::vector<>, iterators, other collections

Evey raw pointer should immediately be given to a smart pointer wrapper (I would start with shared, and consider unique later since it requires explaining std::move and rvalue references). Doing this will make learning C++ feel a lot like learning Java or C#, where you learn the library at the same time as the language. It will take away a lot of the memory work, too, and leave people less worried about gotchas.

I would also work lambdas into the picture the first time we wanted to iterate through a collection and do something to each element.

Disclaimer: I am writing a C++ course for Pluralsight right now and using this approach. The last module is "understanding other people's code" and that is where I will put the confusing stuff like char* strings, manual memory management, pointer arithmetic, and so on.

Update: a few people have asked why the existence of C++0x inspires teaching things that could have been taught with C++03. I think it's a number of things:

  • truly smart pointers, that are collection friendly, take away the need for things like "an array of Employee pointers" that were causing us to always fall back on new/delete, pointer arithmetic etc
  • auto takes away the pain of iterator declarations
  • lambdas make foreaching something an ordinary person would do
  • even something as trivial as parsing >> correctly eliminates the gotcha that would be there when declaring some templates of templates
  • and so on

The way I see it, there are things we could have changed about the way we were teaching C++ some time ago, but some of us held back because we still needed the old-school way for a fallback or because teaching it just involved a lot of arcane knowledge.

|improve this answer|||||
  • 3
    Why do you feel that manual memory management should be taught later? I think it is important to know and it gives more of an appreciation when learning smart pointers. I have had to learn memory management (and char arrays) in C and it has made me appreciate RAII and std::string much more than I think I would if I hadn't had to do it. – Jetti Aug 16 '11 at 13:39
  • 1
    Your examples mostly apply to C++98 vs. pre-standard C++, not C++03 vs. C++11. I suppose given lambda, std::for_each() will be much more popular than it used to be, auto will be very important, and the new function declaration syntax (in conjunction with decltype) will become used quite a lot in template code. Those are things no current C++ book teaches. But, yes, in general I agree with you (+1). When I started to give C++ courses, I started out with Accelerated C++, and even though my course started to deviate more and more from it, it still holds true to the underlying principle. – sbi Aug 16 '11 at 14:26
  • 3
    @Jetti: I rarely ever do manual resource management, and if I do, it's for implementing RAII classes. I do, however, use many of those classes. According to that, the usage of RAII stuff seems more important than the dealing with raw resources and should thus be taught earlier, with more emphasis. – sbi Aug 16 '11 at 14:28
  • 1
    @sbi: I have to agree with you there- most of these examples seem like Modern C++ 101 from 2006, not anything new about C++11. – DeadMG Aug 16 '11 at 18:54
  • 2
    @Jetti: The most important step towards mastering C++ is learning all the ways in which you can avoid manual memory management. It is absolutely something that should be taught "later", once you've learned how far you can go through "automatic" memory management. – jalf Sep 5 '11 at 19:15

Pretty much, yes. The simple fact is that in C++98 and 03, many good practices were fundamentally unusable because of the poor quality of language support for e.g. functional programming. Now that lambdas exist and work, people tend to accept functional interfaces a lot better than they used to, and generic programming is even stronger than before.

In 1998, people were only just beginning to discover how to write high quality, safe, fast code using C++, and a lot of code was "C was Classes". In C++11, it's very different- idioms like copy and swap and the Rule of Three (now Five) are well known and defined, and a lot more resource managing types have become Standard, like shared_ptr and unique_ptr where the previous Standards simply left them as gaping holes.

You can view this question for an excellent list of reference material on C++.

|improve this answer|||||
  • 1
    Actually I would put the beginning of the end of "C with classes" a few years earlier than 1998, but in general you are certainly right, and I wouldn't haggle over half a decade. +1 from me. – sbi Aug 16 '11 at 14:33

I don't know the specific book you mention. But in general you can say, that all the basics about C++ syntax, data types and OOP still hold true. The same should goe for the STL libraries that are mentioned in most beginners books.

Though a book as old as from 1998 may have missed a few updates and developments in C++ programming style, that accumulated in the community over the years. I would look for slightly more up to date resources. There are more than enough free online tutorials and documents that should provide you a good start. Some of them may even mention C++0x.

C++0x will for sure change a lot about how programmers see and use the language in future. But this would influence more complex projects where the new features start to make sense. For a beginner this shouldn't matter and you can concentrate on getting comfortable with the existing concepts, that's already enough to learn. Most beginner books don't go very deep into templates for example, so the new variadic templates are not what you need to know now.

Maybe have a look at a list of changes. At least a few concepts like range based for loops will most likely appear in new tutorials even for beginners. So it's worth to have a look.

|improve this answer|||||
  • Thanks! Do you happen to know of any decent resources online or books? – Jetti Aug 16 '11 at 12:17
  • 2
    No, the cplusplus site is often mentioned as a resource that should never, ever be referred to anyone that you would wish to actually write good code. – DeadMG Aug 16 '11 at 12:43
  • @DeadMG Do you have an alternative website? – TheLQ Aug 16 '11 at 13:18
  • @TheLQ: You'd get further with the MSDN reference, or cprogramming.com. – DeadMG Aug 16 '11 at 14:00
  • @Jetti: I'm not aware of any material for using C++11 to teach C++. Everything I have seen teaches C++11 on top of C++03. For learning the latter see stackoverflow.com/questions/388242/…. – sbi Aug 16 '11 at 14:31

Of course, with regard to anything technology related, being up to date with the latest material is always a smart move, however, the changes introduced in C++11 are designed not to rock the boat. If you're new to C++ (or programming in general), this isn't something I'd worry about.

Additionally, if you're a professional programmer, you can bet you'll be working on someone else's code in the future, so there is always value in understanding the way things work, even if it's a depreciated technique in practice.

|improve this answer|||||
  • Thanks for your response, I figured that it would at least help me with looking at old code when using an old resource. – Jetti Aug 16 '11 at 12:22
  • How could lambda, auto, and asynchronous function execution do anything but "rock the boat"? – sbi Aug 16 '11 at 14:34
  • 1
    I'd argue there's a distinction between the introduction of new tools and a broad shift in design philosophy (like we're seeing with PHP, for example) – leo Aug 16 '11 at 14:45
  • 1
    @leo: I disagree. The introduction of the STL, smart pointers, and rich template facilities has totally changed the mainstream design philosophy of C++. Just about every boost library is totally different from your average C++ library of the 90ies. – sbi Aug 16 '11 at 18:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.