In C++ language the elements of the class can be member functions, sometimes still called methods. They define a set of operations which can be done on the object. Take, for example, a program that makes extensive use of vector calculus. For simplicity, we will only consider a case of the vector in the plane. Each vector can be represented by an object of a class Vector. Our focus will be vectors in Descartes coordinate system where each vector will be represented by two real numbers that is:
·         nx which is a projection on the x-axis,
·         ny which is a projection of a vector on y-axis.
If we want to accomplish scalar multiplication of vectors that could be done by generating the following code.
class Vector {
       float nx, ny;
       void scalarmultiplication(float scalar);
void Vector::scalarmultiplication(float scalar){
       nx *= scalar;
       ny *= scalar;
The definition of one vector and his multiplication in that case looks like this:
       Vector v;
The access to functions of a class is done with previously described operators that we use to access the class members.On the left side of the operator we put the object, reference or pointer on the objects, while on the left side we put the name of member functions. After the name in brackets we need to put real arguments.
During the function call scalarmultiplication() it isn’t necessary to mention the vector to which multiplication is applicable, because it’s already on the left side of the operator for accessing the object of the class. The members ny and ny which are in function calling are members of variable v.
       Vector normal, a2;

The name of the functional member must be unique inside the area of the name inside the class. 
Share on Google Plus