MEMBERS THAT RETRIVE OBJECTS

New members of objects have to be of use, it has to be a way that surrounding code can access specific object members. For that reason we use member selection operators. Before we access the object member, we have to know which object members we’re accessing. Some object is referred using the name of the object, reference or pointer to an object.
When we identify the object using the name of the object or reference, to access members we use operator . (dot), so that the left side of operator is name of the object or reference and the right side of the object is a member which we want to access. For example let’s define and declare the class Computer.
class Computer {
public:
       int memory;
       int disknumber;
       int megabyte;
};
Computer myhomecomputer;
Computer &refComputer = myhomecomputer;
In previous example the keyword “public” means that the members of the class are publically available. Now we are going to expand the object memory of “myhomecomputer” in this way:
       myhomecomputer.memory = 64;
       refComputer.disknumber = 5; // refers to the same object
If we have the pointers which point to an object of class Computer, members can be accessed through the operator -> (type minus – and greater than >). On the left side of the operator we put pointer and on the right side we put name of the member:
       Computer *pokComputer = &myhomecomputer;
       pokComputer->megahertz = 16;

For accessing the members through objects and reference we use the operator . (dot), and in case of access through pointers operator -> (sign minus follow by the sign >).
Share on Google Plus