Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
OBJECT ORIENTED METHODS ASSIGNMENT PART B INDIVIDUAL ASSIGNMENT CHERUKU SHIVANAND (SID 17041136) INTRODUCTION: CONSTRUCTORS: A Constructor is having same name as class and it is a member function. Constructors can be used for initialising, creating, objects of their class type. A constructor cannot be declared as virtual or static, or const, or const volatile. Declaration of a Constructor should be within a class declaration. Default arguments can be included in the constructors. Syntax: class A { public: A( ) ; / / constructor for class A }; Limitations of Constructors: 1) Return values nor return types are not included in the constructors. 2) In constructors pointers and references are not used as their addresses are not taken. 3) The keyword virtual cannot be used for declaring the constructors. 4) If the class objects contains constructors that should not be used in unions. The access rules are same for member functions and Constructors. For example, by using protected access if we declare a constructor, it can be used to create class objects only by derived classes and friends. While creating temporary or local class objects constructors can also be called. A class can contain any number of overloaded constructors inside it, but they are provided with set of parameters which are different. Memory can be allocated automatically for the objects by using constructors. DESTRUCTORS: The inverse of Constructor functions is the "Destructor" functions. To deallocate memory Destructors are used. In a class object when that object is explicitly deleted or it passes out of scope than a destructor is called. There are no return type and no arguments in destructors. Static, volatile, const
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
volatile or const cannot be declared by destructors. Using keyword virtual or pure virtual a destructor can be declared. The access rules are same for member functions and destructors. A destructor which is having same name as its class prefixed by a ~(tilde). For example: classX { public: // constructor for classX X(); // Destructor for classX ~X(); }; In a class if there is no user-defined destructor and one is required, a destructor is declared implicitly by the compiler. This destructor which is implicitly declared in its class is an inline public member. To destroy an object of the destructor’s class type a destructor will be used by the complier than only an implicitly declared destructor will be defined implicitly by the complier. If temporary object or automated object passes out of scope than only destructors are called implicitly. Destructors will be called implicitly for static objects and constructed external at program termination. To use the destructors there are two restrictions: 1) A destructors address cannot be taken.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course CS 541 taught by Professor Dr.marcosrodrigues during the Spring '09 term at SUNY Buffalo.

Page1 / 10


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online