A C++ Cheat Sheet

Many of my students have small, niggling issues with C++ syntax -v- Java syntax. I’ve put together a syntax cheat sheet.

c++-crib-sheet, now updated with all the feedback from comments. Thanks a lot.

I’d appreciate it if people could point out errors and omissions.

8 Responses to “A C++ Cheat Sheet”

  1. Paul Mara says:

    I saw Cian mentioning this site on the minds chat room the other day:
    http://www.parashift.com/c++-faq-lite/

    It looks good so I bookmarked it for myself.

    Your students might find it useful.

  2. DaveMorris says:

    C++ Conditional Statements should be

    std::endl instead of std::end

    I thought the vector iteration didn’t have a header at first pass, since I was reading it as three columns down rather than across. Also I didn’t know that C++ had System.out.println ;)

    For the inheritance and interface examples, is it worthwhile putting the constructors in?

  3. Jonathan says:

    Under “Conditional statements” std::end should be std::endl.

    Maybe it’s worth mentioning import vs #include, and particularly

    Under “Inheritance”, there’s a missing semicolon after ~Widget(). Also, Widget’s destructor should be qualified as virtual (as should Frob’s – and IWidget’s).

    In the right column, you’ve slipped a System.Out.println() into the C++ code. Also, it may be that correctly defined iterators will have a suitably overloaded operator-> so the (*i). may rightly be i-> … I don’t recall for sure though.

    Also, maybe something on pass by value vs pass by reference.

  4. Jean says:

    Shouldn’t the C++ vector iterator be declared as “vector::iterator”?

  5. Jean says:

    Doh! My comment was processed as html…. I typed vector\::iterator

  6. Jean says:

    Doh… vector open angle bracket Widget close angle bracket ::iterator. Sorry for messing up your blog page!

  7. Ulf says:

    The link to the file is invalid. It just downloads a zero byte file. Can you please re-upload it? Thanks.

Leave a Reply