From the course: Learning C++

Unlock the full course today

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

Classes

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