Posts

Showing posts from May, 2018

Member Functions

Member Functions 1.    Defining Member Functions The data members of a class must be declared within the body of the class, whereas member functions of the class can be defined in following ways: ·         O utside the class definition ·         Inside the class definition ·        Outside the Class Definition Member functions that are declared inside a class have to be defined separately outside the class. Their definitions are very much like the normal functions. They should have function header and a function body. An important difference between a member function and a normal function is that a member function incorporates a membership 'identity label' in the header. This label tells the compiler which class the function belongs to. The general form of a member function definition is: return- type class-name :: function-name (argument declaration) { Function Body } The membership label class-name :: tells the compiler that the functi

Objects

    Objects 1.    Creating Objects An object is an instance of class . Once a class has been declared, we can create variables of that type by using class name. An object occupies memory space. For Example: - Item x;                                   // memory for x is created creates a variable x of type Item . In C++, the class variables are known as objects. Therefore, x is called an object of type Item , we may also declare more than one object in one statement, Example: Item x, y, z; The declaration of an object is similar to that of a variable of any basic type. The necessary memory space is allocated to an object at this stage. Note that class specification, like a structure, provides only a template and does not create any memory space for the objects . Objects can also be created when a class is defined by placing their names immediately after the closing brace, as we do in the case of structures. That is to say, the definit

Class

   Class A class is a user defined data that contained data as well as function together . It is a way to bind the data and function together in a single unit. When defining a class, we are creating a new abstract data type that can be treated like any other built-in data type, Generally, a class specification has two parts: - 1.      Class declaration 2.      Class function definitions The class declaration describes the type and scope of its members. The class function definitions describe how the class functions are implemented. The general form of a class declaration in: class class_name { private: Data members; Member functions; protected: Data members; Member functions; public: Data members;       Member functions: }; The class declaration is similar to a struct declaration. The keyword class specifies, that what follows is an abstract data of type class_name. The body of a class is enclosed within braces and te