c#_novice
July 28th, 2008, 06:16 AM
I use forward declaration to include class interface but get errors. Class Contract uses Class Date...
My Date.cpp
#include <time.h>
#include <iosfwd>
class Date
{
public:
Date() {
SetDate( getCurrentTime() );
}
void SetDate(tm curr_tm)
{
day = curr_tm.tm_mday;
month = curr_tm.tm_mon;
year = curr_tm.tm_year;
hour = curr_tm.tm_hour;
minute = curr_tm.tm_min;
local_dt = curr_tm;
}
static tm getCurrentTime()
{
time_t rawtime;
tm* timeinfo;
time( &rawtime );
timeinfo = localtime ( &rawtime );
return *timeinfo;
}
int getDay(){return day;}
int getMonth(){return month;}
int getYear(){return year;}
int getHour(){return hour;}
int getMinute(){return minute;}
tm getLocalDT(){return local_dt;}
private:
int day;
int month;
int year;
int hour;
int minute;
tm local_dt;
};
Contract.h
// Class CONTRACT: Handles the rental contract details
#include <string>
#include <iosfwd>
//#include <iomanip>
//#include <fstream>
//#include <iostream>
//#include "Date.h"
class Date;
class Contract
{
public:
Contract();
void SetContractDetails(Date i, unsigned carR, const std::string& kms, float ratePD,
unsigned lndrID, const std::string& contID, int days);
void SetContractPeriod(Date i_dt, Date r_dt, int d, bool isLtd);
void SetReturnDate();
void DisplayContract();
void Read(std::istream&, Contract&, bool);
void Write(std::ostream&, bool);
const std::string& getContractID() const;
int getContractPeriod() const;
float getRatePerDay() const;
const std::string& getKmType() const;
Date getIssueDate() const;
Date getReturnDate() const;
unsigned getLenderID() const;
unsigned getCarReg() const;
private:
std::string contractID;
Date issued, returned;
unsigned lenderID;
unsigned carRegistration;
int contractDays;
std::string kmType;
float dailyRate;
};
std::istream& operator >> (std::istream& in, Contract& rental);
Errors....
: error C2079: 'Contract::issued' uses undefined class 'Date'
: error C2079: 'Contract::returned' uses undefined class 'Date'
: error C2228: left of '.getDay' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getMonth' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getYear' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getHour' must have class/struct/union
1> type is 'int'
etc...
My Date.cpp
#include <time.h>
#include <iosfwd>
class Date
{
public:
Date() {
SetDate( getCurrentTime() );
}
void SetDate(tm curr_tm)
{
day = curr_tm.tm_mday;
month = curr_tm.tm_mon;
year = curr_tm.tm_year;
hour = curr_tm.tm_hour;
minute = curr_tm.tm_min;
local_dt = curr_tm;
}
static tm getCurrentTime()
{
time_t rawtime;
tm* timeinfo;
time( &rawtime );
timeinfo = localtime ( &rawtime );
return *timeinfo;
}
int getDay(){return day;}
int getMonth(){return month;}
int getYear(){return year;}
int getHour(){return hour;}
int getMinute(){return minute;}
tm getLocalDT(){return local_dt;}
private:
int day;
int month;
int year;
int hour;
int minute;
tm local_dt;
};
Contract.h
// Class CONTRACT: Handles the rental contract details
#include <string>
#include <iosfwd>
//#include <iomanip>
//#include <fstream>
//#include <iostream>
//#include "Date.h"
class Date;
class Contract
{
public:
Contract();
void SetContractDetails(Date i, unsigned carR, const std::string& kms, float ratePD,
unsigned lndrID, const std::string& contID, int days);
void SetContractPeriod(Date i_dt, Date r_dt, int d, bool isLtd);
void SetReturnDate();
void DisplayContract();
void Read(std::istream&, Contract&, bool);
void Write(std::ostream&, bool);
const std::string& getContractID() const;
int getContractPeriod() const;
float getRatePerDay() const;
const std::string& getKmType() const;
Date getIssueDate() const;
Date getReturnDate() const;
unsigned getLenderID() const;
unsigned getCarReg() const;
private:
std::string contractID;
Date issued, returned;
unsigned lenderID;
unsigned carRegistration;
int contractDays;
std::string kmType;
float dailyRate;
};
std::istream& operator >> (std::istream& in, Contract& rental);
Errors....
: error C2079: 'Contract::issued' uses undefined class 'Date'
: error C2079: 'Contract::returned' uses undefined class 'Date'
: error C2228: left of '.getDay' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getMonth' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getYear' must have class/struct/union
1> type is 'int'
: error C2228: left of '.getHour' must have class/struct/union
1> type is 'int'
etc...