Skip to Content
Advanced C++ Programming Cookbook
book

Advanced C++ Programming Cookbook

by Dr. Rian Quinn
January 2020
Intermediate to advanced
454 pages
11h 25m
English
Packt Publishing
Content preview from Advanced C++ Programming Cookbook

How it works...

In this recipe, we will learn how to make a class movable. To start, let's examine a basic class definition:

#include <iostream>class the_answer{    int m_answer{42};public:    the_answer() = default;public:    ~the_answer()    {        std::cout << "The answer is: " << m_answer << '\n';    }};int main(void){    the_answer is;    return 0;}

In the preceding example, we create a simple class with a private integer member that is initialized. We then define a default constructor and a destructor that outputs to stdout when an instance of the class is destroyed. By default, this class is movable, but the move operation mimics a copy (in other words, there is no difference between a move or a copy with this simple example).

To really make this class movable, ...

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

Modern C++ Programming Cookbook

Modern C++ Programming Cookbook

Marius Bancila

Publisher Resources

ISBN: 9781838559915Supplemental Content