Sep 22, 2008 at 4:57pm UTC
Hi all,
I have some problems with my program.
My source is follow
//Address.h
#include<string>
#include<iostream>
class Address
{
public:
Address() : _street(0), _city(0), _country(0){}
Address(char* street, char* city, char* country) : _street(street), _city(city), _country(country) {}
~Address(){std::cout<<"Free memory: "<<std::endl;}
public:
void SetStreet(char* street){this->_street = street;}
char* GetStreet()const{return this->_street;}
void SetCity(char* city){this->_city = city;}
char* GetCity()const{return this->_city;}
void SetCountry(char* country){this->_country = country;}
char* GetCountry()const{return this->_country;}
friend std::ostream& operator<<(std::ostream& os, const Address& add){os<<"Address: "<<add._street<<" - "<<add._city<<" - "<<add._country<<std::endl; return os;}
private:
char* _street;
char* _city;
char* _country;
};
//Common.h
typedef unsigned int BYTE;
enum Method : BYTE{Cash=1, BankTransfer=2, CreditCard=3};
enum OrderStatus : BYTE{Booked=1, BookedNotConfirmed=2, CheckedIn=3, CheckedOut=4, Confirmed=5};
enum RoomType : BYTE {Single = 1, Double = 2, Triple = 3};
typedef unsigned long ULONG;
#define TICKS_IN_DAY 86400 // = 24 * 60 * 60
///////////////////////////
// Hotel.cpp
#include<iostream>
#include<list>
#include<limits>
#include<string>
#include<list>
#include "Common.h"
#include "Address.h"
class Room
{
public:
Room(void);
Room(char rid[3], char* name, RoomType type, BYTE noroom, float price, float taxrate, char* notes)
: _rid(rid), _name(name), _type(type), _noroom(noroom), _price(price), _taxrate(taxrate), _notes(notes){}
void SetRID(char rid[3]){_rid = rid;}
char* GetRID()const{return _rid;}
void SetName(char* sname){_name = sname;};
char* GetName()const{return _name;}
void SetType(RoomType type){_type = type;}
RoomType GetType()const{return _type;}
void SetNoRoom(BYTE noroom){_noroom = noroom;}
BYTE GetNoRoom()const{return _noroom;}
void SetPrice(float price){if(price < 0) _price = 0; else _price = price;}
float GetPrice()const{return _price;}
void SetTaxRate(float taxrate){_taxrate = taxrate;}
float GetTaxRate()const{return _taxrate;}
void SetNotes(char* snotes){_notes = snotes;}
char* GetNotes()const{return _notes;}
public:
friend bool operator==(const Room& lr, const Room& rr){return bool(strcmp(lr._rid, rr._rid) == 0);}
friend bool operator>(const Room& lr, const Room& rr){return bool(strcmp(lr._rid, rr._rid) > 0);}
friend std::ostream& operator<<(std::ostream& os, const Room& room);
private:
char* _rid;
BYTE _noroom;
char* _name, *_notes;
RoomType _type;
float _price, _taxrate;
};
class Hotel
{
public:
static void Initiation();
public:
static void SetName(char* name){_name = name;}
static char* GetName(){return _name;}
static void SetPhone(char phone[15]){strcpy_s(phone, strlen(_phone), _phone);}
static char* GetPhone(){return _phone;}
static void SetFax(char fax[15]){strcpy_s(fax, strlen(_fax), _fax);}
static char* GetFax(){return _fax;}
static void SetAddress(Address add){_address = add;}
static Address GetAddress(){return _address;}
public:
static std::list<Room>& GetRooms(){if(!_rooms) _rooms = new std::list<Room>() ;}
static std::list<Room>& GetRooms(RoomType type);
static BYTE GetRoomCount(){return static_cast<BYTE>(_rooms->size());}
static BYTE GetRoomCount(RoomType type);
static BYTE InsertRoom(char rid[3], char* name, RoomType type, BYTE noroom, float price, float taxrate, char* notes);
static bool UpdateRoom(char rid[3], char* name, RoomType type, BYTE noroom, float price, float taxrate, char* notes);
static bool DeleteRoom(const char rid[3]);
private:
static char* _name;
static char _phone[15], _fax[15];
static Address _address;
static std::list<Room>* _rooms;
};
inline std::ostream& operator<<(std::ostream& os, const Room& room)
{
os<<std::endl<<"Room : ("<<room.GetRID()<<")"<<room.GetName()<<std::endl;
os<<"\t"<<"Type(Single: 1,, Double: 2, Triple: 3): "<<(static_cast<BYTE>(room.GetType()))<<std::endl;
os<<"\t"<<"Number of Room \t: "<<room.GetNoRoom()<<std::endl;
os<<"\t"<<"Price \t: "<<room.GetPrice()<<"\t Tax Rate \t: "<<room.GetTaxRate()<<std::endl;
os<<"\t"<<"Notes \t: "<<room.GetNotes()<<std::endl;
return os;
}
inline void Hotel::Initiation()
{
std::cout<<"Sth here"<<std::endl;
}
inline std::list<Room>& Hotel::GetRooms(RoomType type)
{
std::list<Room>::iterator ite = _rooms->begin();
std::list<Room>* results = new std::list<Room>();
while(ite != _rooms->end()){
if( (*ite).GetType() == type ) results->push_back(*ite);
++ite;
}
return *results;
}
inline BYTE Hotel::GetRoomCount(RoomType type)
{
std::list<Room>::iterator ite = _rooms->begin();
BYTE count = 0;
while(ite != _rooms->end()){
if((*ite).GetType() == type) count++;
++ite;
}
return count;
}
inline BYTE Hotel::InsertRoom(char rid[3], char* name, RoomType type, BYTE noroom, float price, float taxrate, char* notes)
{
Room* r = new Room(rid, name, type, noroom, price, taxrate, notes);
_rooms->push_back(*r);
return static_cast<BYTE>(_rooms->size());
}
inline bool Hotel::UpdateRoom(char rid[3], char* name, RoomType type, BYTE noroom, float price, float taxrate, char* notes)
{
std::list<Room>::iterator ite = _rooms->begin();
while(ite != _rooms->end())
{
if( strcmp((*ite).GetRID(), rid) == 0 )
{
(*ite).SetName(name);
(*ite).SetType(type);
(*ite).SetNoRoom(noroom);
(*ite).SetPrice(price);
(*ite).SetTaxRate(taxrate);
(*ite).SetNotes(notes);
return true;
}
++ite;
}
return false;
}
inline bool Hotel::DeleteRoom(const char *rid)
{
std::list<Room>::iterator ite = _rooms->begin();
while(ite != _rooms->end())
{
if( strcmp((*ite).GetRID(), rid) == 0 )
{
_rooms->erase(ite);
return true;
}
++ite;
}
return false;
}
//main.cpp
#include<iostream>
#include "Hotel.cpp"
int main()
{
Hotel::Initiation();
}
When i run compiler i got this error
Error 1 error LNK2001: unresolved external symbol "private: static class std::list<class Room,class std::allocator<class Room> > * Hotel::_rooms" (?_rooms@Hotel@@0PAV?$list@VRoom@@V?$allocator@VRoom@@@std@@@std@@A) HSM.obj
Error 2 fatal error LNK1120: 1 unresolved externals C:\Users\Google\Documents\Visual Studio 2005\Projects\HMSv10\Debug\HMSv10.exe
i have looked up LNK2001 error code on MSDN website but no solution for this situation. Can any1 help me solve it ?
thanks in advance