课程: Complete Guide to C++ Programming Foundations
免费学习该课程!
今天就开通帐号,24,100 门业界名师课程任您挑!
Function members
- [Speaker] Now we need to add functions for our inventory class to be useful. This includes being able to access the items and capacity from outside the class as these members are private. For this, it's important to note that there are two forms of data access you may want to perform in the external code that uses the class. First, when we assign values, we are writing into the data members. And second, when we print their values, we are reading from them. It is always recommended to keep your data private as much as possible, but remember that classes can have members of two types, data and functions. So a typical means of accessing the data is by defining member functions called setters and getters. Setters write into data members and getters return their values. So let me go to line 11 and start defining our member functions, which by the way will all be public. The first function will add an item to the inventory, so it will be called add item. It will return void and it will…
内容
-
-
-
-
-
-
-
-
-
(已锁定)
Overview of classes and objects5 分钟 13 秒
-
(已锁定)
Data members3 分钟 1 秒
-
(已锁定)
Function members8 分钟 8 秒
-
(已锁定)
Constructors and destructors5 分钟 15 秒
-
(已锁定)
Using classes2 分钟 26 秒
-
(已锁定)
Header and implementation files4 分钟 23 秒
-
(已锁定)
Working with several source files7 分钟 8 秒
-
(已锁定)
Operator overload4 分钟 46 秒
-
(已锁定)
Solution: Create a person class2 分钟 22 秒
-
(已锁定)
-
-
-