From the course: C++ Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Function members - C++ Tutorial
From the course: C++ Essential Training
Function members
- [Instructor] C++ classes can have member functions that act as methods for the class. This is class.cpp from chapter seven of the exercise files. This is a very simple class with one data member. The data member c1val is private by default, that's by design because it's considered best practice to encapsulate object data and to use member functions to access the object data. So there's a couple of member functions, setVal and getVal, which set the value of the private data member and get it respectively. Down here in main we create an object. We use setVal to set the value of the object and we use getVal to get the value of the object and we can build and run this. And you see that our value is 47 as expected. There's an important effect that happens when we const qualify an object. So here we have an object, 01, which is not const qualified. So it's considered mutable as we say. So if I want to create a separate one…
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)
-
-
-