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 - C++ Tutorial
From the course: C++ Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Overview of classes and objects5m 43s
-
(Locked)
Data members3m 36s
-
(Locked)
Function members4m 27s
-
(Locked)
Constructors and destructors8m 7s
-
(Locked)
Operator overloads5m 28s
-
(Locked)
Non-member operators5m 31s
-
(Locked)
Challenge: Non-member operators54s
-
(Locked)
Solution: Non-member operators1m 20s
-
(Locked)
-
-
-