Is this book too out of date?

Hello. I've study design a bit. I've got the general idea.

I'd like to try coding in C++. I don't have much prior programming experience. Although I've played around a bit and messed with compilers.

I've had this book for a while it's: C++ Primer Plus 4th Edition by Stephen Prata. I've done some of the exercises in it and it doesn't seem that hard. But I'd like to pick it up again since I have found more time.

Are the standards in this book too out of date, or should I get something newer to study? Obviously I'm not looking to do anything fancy with programming right now, since I'm a newb; I just want to learn the C++ basics. I actually plan on programming mostly as a hobby; I'm not going to try to make a living at it. I think this book covers C, and adds in C++ toward the end of the book.
C++ Primer Plus is a really bad book. Never trust a book on C++ which starts with C. C++ and C are really different languages.

This is a most knowg book guide: http://stackoverflow.com/a/388282

Mostly look at these:
Programming: Principles and Practice Using C++ by Bjarne Stroustrup
C++ book from language creator. Updated for C++14.

C++ Primer (currently 5th edition) by Stanley Lippman, Josée Lajoie, and Barbara E. Moo
Do not mix up with Primer Plus, which took already known name to feed on unsuspecting buyers. One of the greatest books on C++. Updated for C++11

Accelerated C++ by Andrew Koenig and Barbara Moo
Not updated for C++11. Was the first book to start teaching modern approach to C++. It is book on C++, not programming, so it is way shorter than others, but expects some knowledge (school BASIC course should be enough) from reader. Great if you think that C++ Primer is too slow and explaining obvious things.
@MiiNiPaa
>> C++ Primer Plus is a really bad book. Never trust a book on C++ which starts with C. C++ and C are really different languages.

I have C++ Primer Plus, 6-th Edition. The first chapter is "Getting Started with C++".
And it still teaches C way. It shows new C++ features, and then do not uses them even where they are appropriate, preferring C way.
Even C++11 revemp is done half-heartedly: most C++11 features just put at the back of the book. It teaches outdated approaches and in the end mentions that you will need relearn and change already created habits. Many useful featureas are not mentioned at all, even in places where it would make sense and make code easier.
And my favorit place, which is here from at least fourth edition:
You’ve already seen the dynamic_cast operator.To summarize, suppose High and Low are two classes, that ph is type High *, and that pl is type Low *.Then the following statement assigns a Low * pointer to pl only if Low is an accessible base class (direct or indirect) to High:
pl = dynamic_cast<Low *> ph;
Nobody notice that it is actually backward? (Sure, it will work as written, but then "only" is incorrect here)
Otherwise, the statement assigns the null pointer to pl. In general, the operator has this syntax: dynamic_cast < type-name > (expression)
The purpose of this operator is to allow upcasts within a class hierarchy (such type
casts being safe because of the is-a relationship) and to disallow other casts.
LOLWUT? He got is completely backward. And he does not mention about casting references, and their features.
@MiiNiPaa
Thanks a lot about warning. I will skip this book. :)
I found learning C++ difficult for me. Also, some authors write completely different things. For instance, two books say about pointers and arrays:

1. The book "Understanding and Using C Pointers" (by Richard Reese) in chapter 4 "Pointers and arrays" says:
A common misconception is that an array and a pointer are completely interchangeable.
An array name is not a pointer. Although an array name can be treated as a pointer at
times, and array notation can be used with pointers, they are distinct and cannot always
be used in place of each other. Understanding this difference will help you avoid incorrect
use of these notations. For example, although the name of an array used by itself
will return the array’s address, we cannot use the name by itself as the target of an
assignment.


2. The book "Professional C++", 3-rd Edition, has two sub-chapters (in chapter 22) called "Arrays are pointers!" and "Not All Pointers Are Arrays!".

So, let's take a look closely: "An array name is not a pointer" and "Arrays are pointers!". This is really nice.

Moreover, I would like to learn low-level creating windows through Windows API rather than MFC. But this is just my dream 'cause I understand it'll be hard work. May be you can advice some book which would explain how Windows API works according to creating and manipulating windows. Once again, thanks for help! :)
May be you can advice some book which would explain how Windows API works
Usually two books are recommended: Programming Windows by Charles Petzold and Windows via C/C++ by Jeffrey Richter.

So, let's take a look closely: "An array name is not a pointer" and "Arrays are pointers!". This is really nice.
Richard Reese is correct here. Arrays have they own distinct type, you can cast to and overload functions on, but they also can decay to pointers at slightest provocation.
However you need to actually read what Professional C++ has to actually say. It might be just a flashy title, and chapter itself does explaing difference between arrays and pointers.
@MiiNiPaa
Thanks a lot for titles!
Also in Bill Weinman's video training video "C and C++ Esential Training" (Lynda.com), he says (in 01-About C): "And learning C is an essential first step on a road to learning C++. Let me say this again in a different way: you CAN NOT skip this step. In order to learn C++, you MUST learn C".
C and C++ are different and incompatible languages. Conforming modern C code is likely will not compile with C++ compiler. There is a common subset of C and C++, but those are separate languages. Here is what language author has to say about it:
http://www.stroustrup.com/bs_faq.html#prerequisite

It is more than that. Common C techniques are considered a sign of bad style in C++. You will have to relearn things if you want to apply C knowledge to C++. So C background gives you little bonus to learning C++, compared to time spent learning C
About that training video, when was it made? This is how C++ was traditionally taught, at a time when most people only ever got to use a small fraction of the language and it's power. Today, that is spectacularly bad advice.

Some books that followed that approach were quite good (Thinking in C++ for example) but effective use of C++ has since grown and changed significantly.

The prevalent way with all the modern masters is as mentioned by MiiNiiPaa, with books like Accelerated C++, C++ Primer, etc. If you are new, or even if you're not try PPP2e, you'll enjoy it.

Also C itself is now a very different language, and the latest standard is incompatible with C++ in many ways. If you were to try and learn modern C as a prerequisite to learning modern C++, you would have wasted your time and hopelessly muddied the waters.
@tipaye
The video is updated to C++11.
As for Windows API, it is C. It is full-fledged C. No signs of C++. NULLs, defines, structures. It doesn't use classes at all. It doesn't use the paradigm of OOP. So, if nowadays C is "very different language" and "incompatible" with C++, then why learning C++ at all? To use and understand Windows API, I don't need C++ at all. Am I right?
It is an API. You can use in whichever language you like. You can call WinAPI function from C, C++, Python, Java...
And WinAPI is not a language. You cannot program anything "in WinAPI". YOu can create a program in <some programming language> using WinAPI.

As for Windows API, it is C.
No, It is an API. There are bindings for C/C++ (they are intentionally made compatible with both languages), there are bindings for C#, there are bindings for Java, and you can create your own, if you want.
Here's a quote from Wikipedia Windows API page:

The Windows API (Win32) is primarily focused on the C programming language[2] in that its exposed functions and data structures are described in that language in recent versions of its documentation. However, the API may be used by any programming language compiler or assembler capable of handling the (well defined) low level data structures along with the prescribed calling conventions for calls and callbacks. Similarly, the internal implementation of the API's functionality has been developed in several languages, historically.[3] Despite the fact that C lacks any notion of object-oriented programming, the Windows API as well as Windows itself has sometimes been described as object-oriented. There have also been many wrapper classes and extensions (from Microsoft or other sources) for object oriented languages that makes this object oriented structure more explicit (MSFC, VCL, GDI+, etc.). For instance, Windows 8, while still providing the Windows API, also provides the WinRT API which is implemented in C++[4] and is object-oriented by its design.[4]


@MiiNiPaa, tipaye
Yes, I agree with you that API is just API. But let's take a look under another angle. The C++ has roots in C. The C was the base of C++, so it's correctly to assume that C could be replaced by C++. The C++ has all rights to replace C. What you say about other languages that "there are bindings" (your example - C#) would be incorrect because we pay for marshaling and all sort of conversions between .NET and "unmanaged" code. But I talk about namely C++! Not C#, not VB.NET. See my point? If you insist to forget C, then I can't because to use WinAPI in C++ I will have to learn C (dreaded BOOL, NULL, define etc). Not to go far away, take hPrevInstance from WinMain - it is always NULL, because it comes from Win16! All this garbage must be learned and must be understood, because it's C.
Last edited on
If you insist to forget C
Whaere I said that? I said that you need to learn C++ to use C++. Knowledge of common C subset will come along the way. You won't be well versed in doing things the C way (or it is better to say, you will start using common C approaches later) — raw storage allocation, manual initialization, manual pointer aligment, raw data pointer arithmetic, goto to implement error handling are not needed in C++. Even for manipulating WinAPI. It is written in style more common to C (structured programming) than to C++ (OO approach), but by no means it makes it C. You can still use this API in C++ style programs easily.

hPrevInstance from WinMain - it is always NULL, because it comes from Win16! All this garbage must be learned and must be understood, because it's C.
No it isn't. I made a fulltext search on C11 standard and I can tell for sure that hPrevInstance has no relation to C. It is a pointer, which exist in C++. And you need to learn what it means not because it C, but because it is a part of the API you are trying to use.

dreaded BOOL, NULL, define etc
Those again either parts of the API, or standard C++ features. Defines are discouraged, but are still part of C++, like macros. NULL can be safely replaced with nullptr almost everywhere, and it still a large part of C++, as not everything is updated for C++11.
The question we tried to answer I think is whether you need to learn C first, in order to learn C++.

The answer is an emphatic no!

This is not saying you shouldn't learn C, but you don't need to understand C in order to understand C++. In fact, having learnt C++, you will find it easier to learn C.

The danger is this, if you learn C first, as a way of learning C++, you're likely to try and use C++ the same way you use C. C++ has many features, and fosters a very different mindset and approach to programming. Having first tackled these concepts in C, it is much harder to come around to the C++ way of doing things. This means you most likely will not use many new features, and in particular the new mindset fostered by C++, and will still be stuck with many terrible problems that have plagued C programmers for decades. The reverse is different, having mastered the C++ paradigms, you will be able to do procedural programming in C, in a very different, more modern and effective way.

I believe that learning modern C++ first, will actually make you a better C programmer in the long run.

My advice is to learn both if you have the time and energy, but learn C++ first, and give yourself a lot of practice with it, especially explore generic programming paradigm and use of the standard library, before learning C.

In reality, if you are careful, you can write programs that will be 100% conforming in C++11, C++98, C99 and C89 at the same time, simply by avoiding the incompatible features. Most ANSI C89 conforming programs will compile without change when treated as C++98.

Having said that, C++ provides strong support for generic programming, object oriented programming and procedural programming, meaning you can use these paradigms with ease in C++, they are supported by the language and standard library.

On the other hand you could do OO or generic in C as well, but neither the language nor it's standard library supports this, so you find yourself manually doing the work of a compiler and 100s of expert library authors. It's possible, in the same way it's possible to jump into an active volcano and survive, but it's a hassle and will most likely result in disaster.

Now about the Windows API:
To use and understand Windows API, I don't need C++ at all. Am I right?

Yes, you're right! As pointed out previously, there are thousands of Windows programmers using Javascript, Python, C#, Java, Pascal, every language imaginable, that don't know any C. or C++.

I think I understand where you're coming from though, so let me put it this way:
they are intentionally made compatible with both languages

In the MS documentation explaining the API, the examples are shown using C, and you've seen the function prototypes and data structures all in C - but that is all old C, AFAIK, there is nothing there that is not legal C++. To put it better, There is nothing in there you wouldn't understand if you already know C++.

You may not realise it yet, but what you're worried about isn't programming in C++, it's programming for Windows. You wonder about understanding and effective use of the Windows API, since it appears "to be C", but that worry is unfounded. Remember, you are using the API, not creating it.

Final suggestion, get a copy of one of Ivor Horton's Beginning Visual C++ series, where he teaches both C++ and Windows programming, scan the sections on Windows programming and see if that doesn't set your mind at rest.
@MiiNiPaa, tipaye
Guys, thanks for all the answers and explanations you gave! And I liked your "In fact, having learnt C++, you will find it easier to learn C."

I agree with you 100%. You know, I began learning C, not C++, and the the first book was "Beginning C" by Ivor Horton. When I was reading this book, one of my colleagues came to my office and saw that I was reading this book. And he asked "Why C? There's C++!" Now I understand what you mean. But what I find challenging is the complexity of C++. Since new standards bring on the table new things and shift paradigms, then it's my responsibility to also understand legacy code (for instance, various forms of initialization).

But complexity of the language itself is just one side of coin. There's another side - I should also understand the inner workings of API itself. Since Windows API "is C" (I mean here "raw" API), it doesn't expose its API as OOP. In other words, I just gotta know which function to use instead of using class' methods, as it would be naturally. Rewriting Windows API in C++ can't be realized because so many programs depend on it. I am learning C++ for myself because my job is not about creating software, but we have lots of data which is naturally to explore and process with some program. I read that C++ creates very efficient code, very fast code. But comparing, say, learning C++ and C# (namely learning, not performance), C# could be learned for two weeks. But C++ is another story. There're few people in the world who are truly "know-it-all" persons. That is why I find C++ difficult to learn. Lots of nuances, lots of abilities, lots of responsibility. May be I am wrong, as I am just beginning learning it, but C++ is such complicated because it tries to "generalize" more and more things. From one point of view, this seems to be good, but from the other point of view, people, who read your code, must understand your intentions when they are not so much critical to include them to standard. And the word "responsibility" comes not only from the fact "managing pointers", but from the understanding Standard. You can say that C# is evolving too, but the changes coming are not that vast as of C++. I think of C++ as big cow, which gives tasty and useful milk but requires lots of food and careful managing.
Once again, thanks for explanations! I think I will find my road into understanding C++! Good luck! :)
Topic archived. No new replies allowed.