0

Create copy constructor in class date assume that dd- mm- yy as member

14th Mar 2017, 2:05 AM
Nandhini
2 odpowiedzi
+ 3
Is this what you're asking for? public class date{ private int dd, // day mm, // month yy; // year date(int dd, int mm, int yy){ this.dd = dd; this.mm = mm; this.yy = yy; } }
14th Mar 2017, 2:12 AM
Rrestoring faith
Rrestoring faith - avatar
0
class date{ private int _d; int _m; int _y; //Default constructor date(){ this._d = 1; this._m = 1; this._y = 1900; } //overloaded constructor date(int d, int m, int y){ this._d = d; this._m = m; this._y = y; } //copy constructor date(date &dt){ this._d = dt._d; this._m = dt._m; this._y = dt._y; } void show (){ cout<<this._d<<"-"<<this._m<<"-"<<this._y; } //overloaded constructor void setDate(int d, int m, int y){ this._d = d; this._m = m; this._y = y; } }; int main (void){ date d1(14,3,2017); //overloaded constructor called implicitly date d2=d1 //copy constructor called d1.show(); cout<<"\n"; d2.show(); }
14th Mar 2017, 11:22 AM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar