To avoid data replication some attributes are shared between instances, using static.
These are referred to in UML as having classifier scope.
Class attributes/variables :
Define the data shared by class instances.
Class methods :
Define behaviour of classes that cannot be associated with an instance.
Instance attributes/variables :
Define the data stored by class instances. Instance scope.
Instance methods :
Define behaviour of class instances. Instance scope.
We only have one copy of each function in a class.
The this pointer holds the memory address of the current object that is using the function.
The this pointer is automatically supplied when you call a non-static member function of a class:
For example, clerk.displayValues();
.. is actually displayValues(&clerk);
The actual argument list used by the compiler for displayValues() is displayValues(Employee *this).
Why do you need the bracket?
Because this is a pointer, this.employeeIdNum isn’t and the “.” would take precedence over the *.
Above is another way of accessing a field of a class.
Below we use this to automatically identify context.
In the previous example we used the -> operator (pointer-to-member operator) to access member functions of the entity at a particular address, as specified by a pointer.
(*this).number and this->number are equivalent.
In general for a pointer X we have (*X).x and X->x.