Skip to Content
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
book

C++ Coding Standards: 101 Rules, Guidelines, and Best Practices

by Herb Sutter, Andrei Alexandrescu
October 2004
Intermediate to advanced
240 pages
6h 22m
English
Addison-Wesley Professional
Content preview from C++ Coding Standards: 101 Rules, Guidelines, and Best Practices

32. Be clear what kind of class you’re writing

Summary

Know thyself: There are different kinds of classes. Know which kind you are writing.

Discussion

Different kinds of classes serve different purposes, and so follow different rules. Value classes (e.g., std::pair, std::vector) are modeled after built-in types. A value class:

• Has a public destructor, copy constructor, and assignment with value semantics.

• Has no virtual functions (including the destructor).

• Is intended to be used as a concrete class, not as a base class (see Item 35).

• Is usually instantiated on the stack or as a directly held member of another class.

Base classes are the building blocks of class hierarchies. A base class:

• Has a destructor that is public and virtual ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ Core Guidelines Explained: Best Practices for Modern C++

C++ Core Guidelines Explained: Best Practices for Modern C++

Rainer Grimm
C++ Templates: The Complete Guide, 2nd Edition

C++ Templates: The Complete Guide, 2nd Edition

David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor

Publisher Resources

ISBN: 0321113586Purchase book