set data(1066);
by itself, because a member function is always called to act on a specific object, not on the class in general. Attempting to access the class this way would be like trying to drive the blueprint of a car. Not only does this statement not make sense, but the compiler will issue an error message if you attempt it. Member functions of a class can be accessed only by an object of that class.
To use a member function, the dot operator (the period) connects the object name and the member function. The syntax is similar to the way we refer to structure members, but the parentheses signal that we’re executing a member function rather than referring to a data item. (The dot operator is also called the class member access operator.)
The first call to set data(),
s1.set data(1066);
executes the set data() member function of the s1 object. This function sets the variable some data in object s1 to the value 1066. The second call,
s2.set data(1776);
Saturday, October 18, 2008
Calling Member Functions-2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment