Classic C++ Files: Sixteen Ways to Stack a Cat -- Bjarne Stroustrup

For your Friday reading pleasure, here's a classic paper showing off C++'s flexibility with a wink and a smile.

Although it doesn't exercise the new features of modern C++, we believe all of the code still works. How's that for backward compatibility...

Sixteen Ways to Stack a Cat

by Bjarne Stroustrup

From the article:

This paper presents a series of examples of how to represent stacks in a program. In doing so it demonstrates some of the fundamental techniques and tradeoffs of data hiding as seen in languages such as C, Modula2, and Ada. Since all the examples are written in C++ it also demonstrates the flexibility of C++’s mechanisms for expressing data hiding and access.

... The nine-plus cat lives in this paper are dedicated to Dave McQueen who once in desperation proposed the death penalty for presenting "yet another stack example." Also thanks to Andy for giving me a practical demonstration of the difficulty of stacking cats.

Add a Comment

Comments are closed.

Comments (4)

0 0

Andrea Bigagli said on Mar 7, 2014 02:44 PM:

Nice read, just one doubt: in "8) Packages with Implicit Indirection", on page 7 it reads "Unfortunately C++ does not allow you to define a class ‘‘elsewhere’’ and have its name local to another class".
Isn't this what "pimpl" does, where the implementation class is forward declared inside the "host" class (which holds a [smart] pointer to it) and then defined ''elsewhere'', i.e. in the corresponding cpp file?
Am I missing/misinterpreting something?

Andrea.
0 0

Bjarne Stroustrup said on Mar 7, 2014 04:31 PM:

Please note that paper was written in 1990 - 24 years ago - and partly tongue in cheek. Much have changed since - including terminology.
0 0

Andrea Bigagli said on Mar 8, 2014 02:08 AM:

Oh, I see...
Now that you have made me think about it, I remembered having read this at the time (could it be on the "C++ Report"?), when I started playing with C++ while at the university, but so much C++ crossed my head during these years that I didn't recognize it.
Well, this also means its content (despite terminology) it's still so current that I could read and appreciate it again without realizing it was coming from the past.

Thanks for your reply,
Andrea.
0 0

Bjarne Stroustrup said on Mar 8, 2014 05:05 AM:

From my bibliography (http://www.stroustrup.com/papers.html): B. Stroustrup: Sixteen Ways to Stack a Cat. The C++ Report. Oct 1990. (a somewhat odd paper provided by popular demand).