When using the interval_since member function I get a:
[Linker error] undefined reference to `DigitalTime::interval_since(DigitalTime const&, int&, int&) const' and I'm not sure why. All the files I'm using are below:
///Header file dtime.h:
#include <iostream>
using namespace std;
class DigitalTime
{
public:
void interval_since(const DigitalTime& previous,int& hours,int& mins)const;
//copied from textbook
//should return time change
friend bool operator ==(const DigitalTime& time1, const DigitalTime& time2);
//Returns true if time1 and time2 represent the same time;
//otherwise, returns false.
DigitalTime(int the_hour, int the_minute);
//Precondition: 0 <= the_hour <= 23 and 0 <= the_minute <= 59.
//Initializes the time value to the_hour and the_minute.
DigitalTime( );
//Initializes the time value to 0:00 (which is midnight).
void advance(int minutes_added);
//Precondition: The object has a time value.
//Postcondition: The time has been changed to minutes_added minutes later.
void advance(int hours_added, int minutes_added);
//Precondition: The object has a time value.
//Postcondition: The time value has been advanced
//hours_added hours plus minutes_added minutes.
friend istream& operator >>(istream& ins, DigitalTime& the_object);
//Overloads the >> operator for input values of type DigitalTime.
//Precondition: If ins is a file input stream, then ins has already been
//connected to a file.
friend ostream& operator <<(ostream& outs, const DigitalTime& the_object);
//Overloads the << operator for output values of type DigitalTime.
//Precondition: If outs is a file output stream, then outs has already been
//connected to a file.
private:
int hour;
int minute;
};
//-------------------------------------------------------------------
//DISPLAY 12.2 Implementation File for DigitalTime
//Implementation file dtime.cpp
//This is the IMPLEMENTATION of the ADT DigitalTime.
//The interface for the class DigitalTime is in the header file dtime.h.
#include <iostream>
#include <cctype>
#include <cstdlib>
#include "dtime.h"
using namespace std;
//These FUNCTION DECLARATIONS are for use in the definition of
//the overloaded input operator >>:
void read_hour(istream& ins, int& the_hour);
//Precondition: Next input in the stream ins is a time in 24-hour notation,
//like 9:45 or 14:45.
//Postcondition: the_hour has been set to the hour part of the time.
//The colon has been discarded and the next input to be read is the minute.
void read_minute(istream& ins, int& the_minute);
//Reads the minute from the stream ins after read_hour has read the hour.
int digit_to_int(char c);
//Precondition: c is one of the digits '0' through '9'.
//Returns the integer for the digit; for example, digit_to_int('3') returns 3.
int main()
{
DigitalTime time1,time2(13,50),time3;
cout<<"this program will test the DigitalTime class\n";
cout<<"Enter a time in the format(hr:min)time3: ";
cin>>time3;
cout<<"all of the following will use the overloaded <<\n";
cout<<"constructor DigitalTime()time1="<<time1;
cout<<"\nconstructor DigitalTime(int,int)time2="<<time2;
cout<<"\noverloaded DigitalTime >> time3="<<time3;
if (time2==time3)
{cout<<"\ntime2 = time3";}
else
{cout<<"\ntime2 != time3";}
cout<<"\ntesting the advance(min)";
int mintoadd;
cout<<"\nhow many min's to add?";
cin>>mintoadd;
cout<<"test3 was "<<time3;
time3.advance(mintoadd);
cout<<" now its "<<time3;
cout<<"\ntesting the advance(hour,min)";
int hourstoadd;
cout<<"\nhow many hours to add?";
cin>>hourstoadd;
cout<<"how many min's to add?";
cin>>mintoadd;
cout<<"test3 was "<<time3;
time3.advance(hourstoadd,mintoadd);
cout<<" now its "<<time3;
cout<<"\ntesting interval() now";
int hours,mins;
DigitalTime previous(2,20);
time3.interval_since(previous,hours,mins);
/* things to do
get interval_since member function to work
*/
system("PAUSE");
return EXIT_SUCCESS;
}