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 this, ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.