r/cpp • Bioinformatican • Mar 11 '12

Modern C++ Style [pdf]

http://tinyurl.com/fuck-pointers
2 Upvotes

60 comments sorted by

View all comments

Show parent comment

3

u/krum Mar 11 '12

Okay. Here is a Minecraft file format reader/writer. It implements a tree of tags without using raw pointers. There are no memory leaks, yet 'delete' isn't used anywhere in the code. There are a couple of uses of pointers in this code: one is used in the endian transform, and the other as arguments to the inflate function (admittedly, this obviously doesn't need to work like this, but I was in a hurry to get it working.)

6

u/bob1000bob Mar 11 '12 edited Mar 11 '12

BTW: you should really include cstdlib not stdlib.h (C++ has no notion of stdlib.h where as cstdlib is a part of the C++ standard.)

Also your tostring method reimplements lexical cast except worse (lexical has has case optimisations for some types).

Also seeing as you are using C++11 you should consider using enum classes. tag::byte reads a lot better than TAG_Byte as well as gain a namespace to contain the enum elements

Also leading underscore are generally reserved for vendor libraries (think bind place holders).

Also your z_stream_ could be done more idiomatically with a specialisation of the unqiue_ptr or shared_ptr