Click here to Skip to main content
15,917,709 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Link error: LNK 2001 unresolved symbol Pin
Cedric Moonen25-Sep-08 1:01
Cedric Moonen25-Sep-08 1:01 
GeneralRe: Link error: LNK 2001 unresolved symbol Pin
PCuong198325-Sep-08 6:53
professionalPCuong198325-Sep-08 6:53 
QuestionShow a button in pressed state using CMFCToolbar Pin
Farhat Aisha24-Sep-08 23:56
Farhat Aisha24-Sep-08 23:56 
AnswerRe: Show a button in pressed state using CMFCToolbar Pin
Redeye9225-Sep-08 1:57
Redeye9225-Sep-08 1:57 
GeneralRe: Show a button in pressed state using CMFCToolbar Pin
_Marina_2-Dec-09 2:53
_Marina_2-Dec-09 2:53 
GeneralRe: Show a button in pressed state using CMFCToolbar Pin
Redeye922-Dec-09 3:17
Redeye922-Dec-09 3:17 
GeneralRe: Show a button in pressed state using CMFCToolbar Pin
_Marina_2-Dec-09 3:32
_Marina_2-Dec-09 3:32 
QuestionLink error: LNK2001 Fatal error Pin
PCuong198324-Sep-08 23:43
professionalPCuong198324-Sep-08 23:43 
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=""> > * 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 ?
but when i use vs 2005 to compile i got LNK2001 error, but when i use vs 2008 to compile , i got no error, this program run normally ?
i dont know why ? can any1 answer this ?
thanks in advance
AnswerRe: Link error: LNK2001 Fatal error Pin
Rajesh R Subramanian24-Sep-08 23:46
professionalRajesh R Subramanian24-Sep-08 23:46 
AnswerRe: Link error: LNK2001 Fatal error Pin
Cedric Moonen24-Sep-08 23:49
Cedric Moonen24-Sep-08 23:49 
AnswerRe: Link error: LNK2001 Fatal error Pin
toxcct25-Sep-08 0:05
toxcct25-Sep-08 0:05 
GeneralRe: Link error: LNK2001 Fatal error Pin
Rajesh R Subramanian25-Sep-08 0:25
professionalRajesh R Subramanian25-Sep-08 0:25 
QuestionFunctions in C Structure Pin
msr_codeproject24-Sep-08 23:38
msr_codeproject24-Sep-08 23:38 
AnswerRe: Functions in C Structure Pin
toxcct24-Sep-08 23:46
toxcct24-Sep-08 23:46 
AnswerRe: Functions in C Structure Pin
CPallini25-Sep-08 1:57
mveCPallini25-Sep-08 1:57 
Questionsample application for connecting to sql server database in ATL. Pin
V K 224-Sep-08 23:34
V K 224-Sep-08 23:34 
AnswerRe: sample application for connecting to sql server database in ATL. Pin
SandipG 24-Sep-08 23:36
SandipG 24-Sep-08 23:36 
GeneralRe: sample application for connecting to sql server database in ATL. Pin
V K 224-Sep-08 23:46
V K 224-Sep-08 23:46 
GeneralRe: sample application for connecting to sql server database in ATL. Pin
SandipG 24-Sep-08 23:49
SandipG 24-Sep-08 23:49 
GeneralRe: sample application for connecting to sql server database in ATL. Pin
V K 224-Sep-08 23:57
V K 224-Sep-08 23:57 
GeneralRe: sample application for connecting to sql server database in ATL. Pin
toxcct25-Sep-08 0:03
toxcct25-Sep-08 0:03 
GeneralRe: sample application for connecting to sql server database in ATL. Pin
Cedric Moonen24-Sep-08 23:53
Cedric Moonen24-Sep-08 23:53 
QuestionQuery about "Fibers" Pin
ramana.g24-Sep-08 23:25
ramana.g24-Sep-08 23:25 
AnswerRe: Query about "Fibers" Pin
SandipG 24-Sep-08 23:31
SandipG 24-Sep-08 23:31 
GeneralRe: Query about "Fibers" Pin
ramana.g25-Sep-08 0:34
ramana.g25-Sep-08 0:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.