Date Class: Using a class

Look at the code for the toString method:

1
2
3
4
5
string Date::toString() const { 
   std::ostringstream oss;  //a stream to append the values
   oss<<month<<"/"<<day<<"/"<<year;
   return oss.str();   
} //toString 
CODE

In this method, we are writing to an output string object and returning the string that is created.

Notice that this function does not have any parameters. When you call it you do not send it any arguments. Unlike most functions, the methods of a class have full access to all of the class's member variables and functions and do not need to receive those values as arguments.

NEXT: Better methods