From the course: Learning C++
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Classes
- [Instructor] Classes are basic elements of object oriented programming. They are intended for implementing models. They contain two types of members, data and functions. And just to be clear, classes mean the same thing in C++ as in Java or Python. So I'd like to start with the previous example where we modeled the cow with a struct. I want you to see how similar classes and structures can be. So the first thing I'll do is go to line 10 and change the struct keyword to class. That's almost it. In fact, let's try it. We got some errors. The first one reads "cow:age is private within its context," and the second one reads "member cow:age is inaccessible." That's because in the main function, I'm trying to access the cow's members, but by default class members are private. So with this error, we see that the class is actually doing its job of hiding its members from the outside world. So for you to see how this class may…
Contents
-
-
-
-
-
(Locked)
Structures2m 29s
-
(Locked)
Classes6m 47s
-
(Locked)
Using classes2m 1s
-
(Locked)
Header and implementation files4m 12s
-
(Locked)
Using several source files6m
-
(Locked)
Pointers5m 17s
-
(Locked)
Using objects with pointers4m 21s
-
(Locked)
References4m 25s
-
(Locked)
Vectors3m 35s
-
(Locked)
Using objects with vectors2m 45s
-
(Locked)
Challenge: Create some classes1m 32s
-
(Locked)
Solution: Create some classes1m 48s
-
(Locked)
-
-
-
-