Reviewing structures
We have already seen one mechanism in C++ to encapsulate data: struct. A structure allows you to declare data members that are built-in types, pointers, or references. When you create a variable from that struct, you are creating an instance of the structure, also known as an object. You can create variables that are references to this object or pointers that point to the object. You can even pass the object by value to a function where the compiler will make a copy of the object (it will call the copy constructor for the struct).
We have seen that with a struct any code that has access to an instance (even through a pointer or reference) can access the members of the object (although this can be changed). Used like ...
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.
Read now
Unlock full access