Special member functions in C++

Slide header

Masterclass on special member functions C++.

Abstract

All class types in C++ have a set of non-static special member functions. Among them are the constructor, destructor, copy constructor and copy assignment operator. In C++11, move semantics were introduced, and the move constructor and move assignment operator were added. Special member functions, when not defined explicitly, may be automatically defined by the compiler. But this is not always the case. Exactly when are they defined, and when not? What is the rule of all or zero? And is it any good? Did you know there are about eight different forms of constructors? And when it comes to copy/move operations, do you know when you need to implement them yourself? And how? In this session, I will guide you through the wonderful world of special member functions. We will look into definition rules, constructor forms, copy/move operations, design patterns, testing and more. As a C++ software engineer equipped with a clear understanding of special member functions, you will be more confident and effective.

Audience

This session is for professionals in software engineering, level novice to advanced, interested in C++. Are you a beginner or novice in C++? This session will show you the basics, as well as many in-depth subtleties, and of course point you in the right direction to go about exploring yourself. Are you an advanced, experienced C++ engineer? Use this session to refresh your knowledge and acquire new details or perspectives. There’s something here for everyone!

Topic listing

These are the main topics addressed in the talk:

  1. Special Member Function (SMF) fundamentals
  • SMF: constructors
  • SMF: destructors
  • SMF: copy operations
  • SMF: move operations
  • SMFs and composition
  • SMFs and inheritance
  • SMF declaration rules
  • Copy vs move and fallback
  • Porting legacy code
  • Rules for defining SMFs
  1. Implementation guidelines
  • Constructor guidelines
  • Destructor guidelines
  • Copy operations
  • Move operations
  1. Tooling and best practices
  • SMFs in design patterns
  • SMFs and testing