课程: Complete Guide to C++ Programming Foundations

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Function members

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…

内容