return values are for having function output. Not output to the user, but output to the program. You said you had 6 years Java experience so I figured you knew this already, but I'll go over it just in case...
For example, a function which sums two integers might return an integer:
1 2 3 4 5 6 7 8 9
|
int add(int a, int b)
{
return a + b; // returns an int
}
int main()
{
int sum = add(5,3);
}
|
In this example, 'add' returns the sum of a and b (which in this case are 5 and 3). Therefore 8 is returned, which is what gets assigned to the 'sum' variable.
So ask yourself this: What information does 'display' need to pass back to the program? I can't think of anything, really, so it makes sense for it to be a
void
function (ie: returns nothing).
|
void display(); // <- make it a void
|
As for 3 is there a way to display a msg during the deconstruction of the methods? |
Well the methods/functions don't destruct, the objects do. But yes, you simply have to pause the program with your cin.get() line
after they are destroyed. You can do this by putting them in a smaller scope which will expire before cin.get() is executed.
One way to do this is to simply add another set of {braces}
1 2 3 4 5 6 7 8
|
int main()
{
{
Hen hen1;
} // hen1 is destroyed here, dtors message is printed
cin.get(); // program paused here
}
|
Another way would be to put everything in a separate function:
1 2 3 4 5 6 7 8 9 10
|
void runprogram()
{
Hen hen1;
} // hen1 destroyed here
int main()
{
runprogram();
cin.get();
}
|