The member functions in the small obj class perform operations that are quite common in classes: setting and retrieving the data stored in the class. The set data() function accepts a value as a parameter and sets the some data variable to this value. The show data() function displays the value stored in somedata.
Note that the member functions set data() and show data() are definitions in that the actual code for the function is contained within the class declaration. (The functions are not definitions in the sense that memory is set aside for the function code; this doesn’t happen until an object of the class is created.) Member functions defined inside a class this way are created as inline functions by default. (Inline functions were discussed in Chapter 5, “Functions.”) We’ll see later that it is also possible to declare a function within a class but to define it elsewhere. Functions defined outside the class are not normally inline.
Monday, October 13, 2008
Member Functions Within Class Declaration
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment