Settings

Theme

C++ Language Quick Guide

viptechworld.blogspot.com

58 points by TheVip 9 years ago · 27 comments

Reader

copperx 9 years ago

I just want to point out that Stroustrup's A Tour Of C++ is an excellent quick guide and it does include C++11 features.

  • bstamour 9 years ago

    I've found the C++ Standard Library 2nd Edition to be an excellent companion to Stroustrup's Tour of C++. It does a good job of preventing you from reinventing wheels that others have already built for you.

bstamour 9 years ago

Please update the section on storage classes. Auto is no longer a storage class, but a keyword for automatic type deduction. Also, register has recently been deprecated as well, if I remember correctly.

  • Impossible 9 years ago

    This appears to be a C++03 guide, as it doesn't mention any C++11 features (no range based for). To be fair it is definitely a "quick" guide, and doesn't cover enough to actually be productive in C++ (pointers\memory allocation and references are missing...), but you're right that auto and register are the only things that appear to be explicitly wrong, instead of wrong by omission.

    • stinos 9 years ago

      doesn't cover enough to actually be productive

      Well probably it would be sufficient to write simple programs. But maybe this guide is just too quick in that it just covers some basic syntax but leaves out a lot of goodies which actual programs use (no containers/algorithms at all, indeed no C++11 and beyond which is imo a shame for any recent C++ guide - there's not even any mentioning of it), doesn't adhere to current best practices (take 'double getVolume(void)': void argument has no place in C++ and should arguably be const, no error checking on stream methods) and seems too lack crucial information (no mention of heder files, no mention of how to get the samples compiled).

    • lomnakkus 9 years ago

      Indeed, this is an awful "guide".

      EDIT: ... because a) it's extremely outdated, and b) it doesn't even give you the basics.

Cieplak 9 years ago

Another cool resource:

https://github.com/rigtorp/awesome-modern-cpp

GhostVII 9 years ago

Does this guide have anything about references? Didn't find anything about that, but maybe I missed it, I think its a pretty important topic to cover. Also didn't see anything about the different types of constructors.

alexeiz 9 years ago

This guide is so primitive that it cannot be called useful. It can possibly be harmful, though, to those who don't know the language well and use this guide as a sole source of information.

minipci1321 9 years ago

> C++ is a superset of C, and that virtually any legal C program is a legal C++ program.

This is not true. One example, void* pointers are not automatically converted to "narrower" types in C++ as they are in C.

  • saghm 9 years ago

    Syntactically, C++ is a superset of C though, right? I can't think of any C syntax that's not valid C++, but I'm not exactly am expert in either

    • minipci1321 9 years ago

      > I can't think of any C syntax that's not valid C++,

      enum toto { a = 1 }; enum toto b = 1;

      Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code).

      Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be compiled as C++.

    • bstamour 9 years ago

      C supports variable-length stack-allocated arrays, while C++ doesn't. So code like

          void f() {
              int x;
              scanf("%d", &x); // read from user
              int numbers[x]; // dynamic
          }
      
      is legal C, but not C++.

      Also, the C "restrict" keyword doesn't exist in C++ either. Add in C's looser typing rules regarding conversions, and C and C++ are basically sibling languages at this point. Their common ancestor language being K&R-era C.

      • saghm 9 years ago

        > C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > }

        I just pasted this in a file (and added `#include <cstdio>`) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?

        • bstamour 9 years ago

          That's because gcc supports it as an extension to C++. It's not an official part of the language, and using it in C++ code is therefore not portable across compilers/platforms.

          • saghm 9 years ago

            clang++ seems to work as well. I don't have a Windows machine handy to try MSVC, though

    • minipci1321 9 years ago

      > I can't think of any C syntax that's not valid C++, enum toto { a = 1 }; enum toto b = 1;

      Fixing versions of both standards could bring in more examples (like trailing comma in enums and use of the names reserved in C++, by the C code).

      Overall, ironically, as typing is stronger in C++ (which I agree is a non-syntactic change), poor C code (using lots of unjustified casts), will require less modifications to be compiled as C++.

  • EpicEng 9 years ago

    >"virtually"

    There are differences, but they are few and far between.

    • minipci1321 9 years ago

      That does disqualify C++ as the __superset__ of C doesn't it?

      • lomnakkus 9 years ago

        I offer you the infamous phrase "extended superset" made famous in the world of SQL databases :).

        (Of course, you're right.)

      • flukus 9 years ago

        C++ is a subclass of C that violates the liskov substitution principle.

blt 9 years ago

This looks more like an exam review study guide than an attempt to teach the language.

PopsiclePete 9 years ago

This is kind of ... crappy. Sorry. It might have been semi-useful in 2004 or so, but now...woefully outdated and inadequate to get anyone up-to-speed. I'd say it's actually harmful.

dotdi 9 years ago

Call me nitpicky, but you lost me at `Box Box1;`

Instance names should be lowercase, for God's sake.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection