C++ Syntax Quick Reference

I wrote a 4-page quick reference for C++ including some C++0x. Only syntax is covered.

Since it may be helpful, and it is more complete than what I could find online, here is the link:


Looks like a cheat sheat for a final exam.
[static] <T> <var> [(<LE>)|=<C>()]; // <C>()

Maybe it's just me, but I find this kind of breakdown to be 1000000x more confusing than the actual syntax.

I've seen this kind of description in other technical docs as well (MySQL documentation) and it was about as useful to me as an infected toenail.

I dunno... maybe I'm in the minority?
Last edited on
Yes, you are right. I will improve it and hopefully remove the confusion! Thanks for the reply.
I agree.

There are also omissions I noticed.
I inserted two examples. Of course, the syntax is immense and some corners had to be cut. However, I will fill any important gap, if someone is kind enough to point it out. The overlapping between classes and structs is solved by just using structs. This is actually the trend in the book "Elements of Programming" by Stepanov and McJones.

Fonts are also not great and will re-type it in Latex with the Microtype package.

As for the omissions, please tell me what is really lacking, I will insert any relevant data.

Last edited on
2.1 function pointer types, pointer-to-member types, pointer-to-member-function types

don't address the volatile keyword

don't address placement new

2.5 see comment to 2.1

missing all bit-wise operations |, &, ^, ~

statements re: when to use static_cast, reinterpret_cast need clarification

missing const_cast

4.3 missing volatile; those aren't the ONLY types; you could pass an int**, int ***, int* const* const*, etc etc etc

you don't talk about the seldom-used comma operator

usage of template function (4.6) is not entirely accurate; it is not always necessary to explicitly specify the types

5.1 is true only if you mention about implicit conversion to bool, since I could also put an integer expression there

5.2 default

5.3, 5.4 see 5.1

5.5 needs clarification of <initialization> and <incrementation> etc, since I can put multiple statements
there separated by commas.

6.2 access specifiers may include the keyword virtual

6.2 it is valid to declare a method pure virtual AND provide an implementation for it. Your syntax implies one or the other

You don't talk about the member access operators .* and ->*

6.6 If you are recommending an object be less-than comparable and equality-comparable, then you should support
all of the operators, <=, >=. But most of your recommendations are not generally true anyway.

explicit needs more description (when to use it)

default arguments to functions, member functions missing

your copy constructor isn't the only copy constructor. See std::auto_ptr for example.

your assignment operator isn't the only assignment operator, either, and in fact, I wouldn't even
recommend that signature (which will change your recommended implementation).

you don't talk about the typename keyword, or about template templates.

try, catch, throw missing

if you're including C++0x, then you need syntax for lambda functors, decltype, and the new
way of declaring functions using -> to indicate return type.

you don't talk about the "using" keyword by itself

you don't talk about creating your own namespace, named and unnamed.

Dereference operator

unions, enums


just off the top of my head. I may think of more later.
ternary operator (?:)

sizeof keyword

namespace X = Y; syntax

unary minus, unary plus (don't have your doc open now to see if you at least hit unary minus)

integral and floating point constants (ie, 42 vs. 42U, etc)

string constants, character constants

escape characters \n, \r, \0, \", \', etc

hexadecimal constants, octal constants

preprocessor directives #if, #ifdef, #ifndef, #if defined, #if !defined, #endif, #else, #define, #undef

stringize operator (preprocessor) (#)

token concatenation (preprocessor) (##)

still thinking...
Several corrections were made thanks to your generous list of corrections. Of course there are still many imperfections, pointed out in comp.lang.c++.moderated and by yourself. I will do the Latex document ASAP, and am *grateful* for your comments.

The language appendix in Stepanov and McJones "Elements" (made also by B. Stroustrup) is a gem of conciseness and rigor. Some inspiration will come from there...

The namespaces are actually a severe lacuna.


P. Areias
Since part of the criticism was actually fair and to-the-point, a new Guide was written. I spent a lot of time with self-criticism, and clearly it is now more complete than what is already available online.

However, perfect it is not, nor complete. Toward the former goal, please see it at:


Some of the "completeness obsession" of jsmith was avoided. Not all preprocessor directives are required, templates are *very incomplete*, etc.

However, for a syntax quick reference guide, it looks (at least to my eyes!) "sufficient".

Thank you for the previous criticism.
Last edited on
Topic archived. No new replies allowed.