10. Non-regular Data Members

Thus far, we spoke about mutable non-static data members like integers, doubles, or strings. Such objects are regular, meaning they are copyable, default constructible, and equally comparable. In C++20 there’s even a concept for that purpose: std::regular, see @C++Reference.

However, you can also have other categories of objects in a class. For example, a custom type might contain constant data members, pointers, references, or moveable only fields like unique pointers or mutexes. For such members, we have immediate issues with default copy constructors (the compiler won’t create them).

In this chapter, we’ll shed some light on such cases.

Constant non-static data members

Content available in the full version of the book.

References as data members

(*) this section will be added in the future.

Pointers as data members

(*) this section will be added in the future.

Moveable-only data members

(*) this section will be added in the future.

Summary

Having discussed other categories of non-static data members, we can now examine static data members. How to use them in Modern C++? See the next chapter.