My problem is I am calling a method in my main but this method doesn't have any code written in it, and yet I am getting an output of numbers approximately 10 digits long, and a negative value.

For example, in my main I have:

Date d1(9,20,2011); // Date is an object that requires a month,day,and year
Date d2(10,1,2011);

cout << d1.dayDifference(d4) << endl;

Then in my .cpp for the dayDifference method I have written:

int Date::dayDifference(const Date& d) const
    //lots of commented out code

My Date object works fine, I overloaded the pre-increment and post-increment operators, and those work fine too, and I have around 20 methods I wrote that use all of this, and yet this dayDifference method, when called, outputs a long negative number. And when I wrote in the code for that method "cerr << help; ", It then outputted the word "help" along with a long positive number.

The output is the same number each time I run it, but it shouldn't be outputting anything since there is no code inside.

Thanks for your help, and I will happily clarify anything

Actually my fiance just explained it to me "Because you don't have a return statement. C++ just makes room for a return variable and if you don't return anything, whatever is in that place in memory (in your case a very long negative number) will be returned."

dayDifference() returns an int value in all cases. Since you didn't specify what that value is, it's garbage.

I thought that it may be a garbage value because we have arguments in the juncton ,the memory has allocated for those variables and has also created memory for the function. the output may bet that memory reference

It may or may not correct I told with my guess

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.