![]() |
| ||
| Problem with constructor #include <iostream> I have problem doing a set date for the above codes. every time i invoked the setDateMenu(Date myDate) to set a new date to my object myDate, it manages to take in the correct day,mth and year (I did a cout at void Date::setDate(int inDay,string inMth, int inYear) It shows the new day,mth and year set. However, when i did a print date (option B), the new date values are still not saved into the dates and it still prints the default date value which is 01-Jan-1990. Anyone got any idea where the codes went wrong and why the new values of the day,mth and year aren't passed into the object? |
| ||
| Re: Problem with constructor Your program does not include <string> for std::string class, so how in the world are you getting it to compile????? Don't attempt to execute a program that contains compiler errors or warnings. Yes, warnings in your code are usually errors too. |
| ||
| Re: Problem with constructor void setDateMenu(Date myDate);You pass Date by value so set a new date to Date copy. The original object is intact. Pass by reference: void setDateMenu(Date& myDate);Common error... I hope now you know that argument passed by value in C and C++ ;)... |
| ||
| Re: Problem with constructor Thanks for the help. i made a reference variable to myDate and it worked. |
| ||
| Re: Problem with constructor Yes, rather! It would be surprising if it didn't work ;) |
| All times are GMT -4. The time now is 9:47 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC