Constructors and Destructors
-
Upload
jaikumarguwalani -
Category
Documents
-
view
2 -
download
1
description
Transcript of Constructors and Destructors
CONSTRUCTOR AND DESTRUCTOR
CONSTRUCTOR AND DESTRUCTOR
1. Point out the errors, if any, in the following program.class date{private:int day,month,year;date(){day = 2;month = 10;year = 2008;}};void main(){date today;}Error : The default constructor is defined under private section; so it is not accessible in function main( ).
2. Point out the errors, if any, in the following program.class value{private:int i;float f;public:value(){i = 0;f = 0.0;return 1;}};void main(){value vi;}Error : The constructor should not return any value. Here constructor contains return statement.
3. Read the following code segment.#include class sample{int x, y;public: sample(int a = 10, int b = 20) {x = a;y = b; } void show() {cout