Home » Learn C++ » Declaring Objects and Calling Member Functions

Declaring Objects and Calling Member Functions

Declaring Objects of a Class:

            The objects of a class are declared in the similar way as the variables of any data or structure type are declared. When a class is defined, no space is reserved for it in the memory. It only provides information how its object will look like. When an object of a class is declared, a memory space is reserved for that object.

 

The syntax to create objects of class type is:

class_name_object_names separated by commas;

For example, to define an object aniv of class cdate, the statement is written as:

cdate aniv;

 

In the above statement one object aniv is declared of class “cdate”. It is the declaration of an object that actually creates an object in the memory.

 

Calling Member Functions:

             The member function of a class is called in a similar way as member or data item of a structure is called. The member function is called through an object of the class. The dot operator is used. The dot operator connects the object name and the member function.

The general syntax to call a member function is:

object_name.member [with arguments in case of a function]

 
For example, if “add” is the name of the object and “pdate” is the member function then the member function is called as shown below:

add.pdate ( );

 

The dot operator is also called the class member access operator. Only those member functions can be accessed from outside the class with the dot operator that has been declared as public.

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.