May 2012
Intermediate to advanced
679 pages
16h 56m
English
Normally, we initialize local or global variables at the time of declaration. However, data members cannot be initialized in this way. For initialization of data members of the objects, C++ has introduced a special method called constructor. The primary purpose of the constructor is to initialize the object at the point of creation.
If we do not initialize the object, it will contain absurd values. Let us check it by a program.
Problem: Write a program to demonstrate that un-initialized objects contain arbitrary values.
Solution: We will define a class Date and check the result. See Program 6.1.
// object1.cpp#include<IOSTREAM.H>class Date { private: int day, month, year; public:
Read now
Unlock full access