From the course: C++ Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Data members

Data members

- [Instructor] C++ classes are based on C structures. In fact, you can create a class using either the struct or class keyword. This is struct-class.cpp from chapter seven of the exercise files. And you see that I have a structure here with three data members ia, ib, ic, all ints. And our struct is called A. And down here in main I declare an object based on our struct A and I initialize it with three values. And then I print it out using these three data members. Structure members are accessed with the dot operator also known as the element selection operator or the member operator. So I can build and run this, and you can see the result. Struct and class are identical with one difference. If I change this to class, you'll notice that this no longer works because these are now private members. The difference between class and struct is that class defaults to private visibility whereas struct defaults to public…

Contents