Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

Hi,i have a problem with this code ,it aborts but i don't know why,can any 1 help me? #include #include #include #include #include using namespace std; class year { public: int y; vector month ; vector day ; year(int YE,vector* M,vector* D): y(YE) { M = new vector(12) ; D = new vector(12) ; } year() {}; }; void main(){ year Y; cin>>Y.y ; if(Y.y==1992) Y.month[3]=8; else Y.month[3]=9; cout<

OpenStudy (anonymous):

Hi! In the year class you have 2 constructors, when you create object "Y" with the statement year Y; the second constructor is called (the one that does nothing). So neither of "month" or "day" is constructed properly. When you access to "month" or "day", it will give unexpected results. I believe that the 2nd constructor was actually a destructor, you just forgot the "~" before it :) . Also, in the first contructor, you only initialized y, you did nothing to "month" and "day". Anyway, here is my code for the year class: class year { public: int y; vector<int> month ; vector<int> day ; year(){ y = 0; month = vector<int>(12); day = vector<int>(12); } ~year() { }; }; I hope it helps! :)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!