I am trying to compile a code that utilises an array of 5 'hotel' objects as below:

#include "Hotel.h"

using namespace std;

int main()
{
	Hotel *hotels = new Hotel[5];

	hotels[0] = new Hotel("Hershey");
	hotels[1] = new Hotel("Milton");
	hotels[2] = new Hotel("Sheraton");
	hotels[3] = new Hotel("BestWestern");
	hotels[4] = new Hotel("DaysInn");

	for(int i = 0; i < 5; i++)
		hotels[i].print();

	return 0;	
}

Hotel.h:

#ifndef HOTEL_H
#define HOTEL_H

#include "DLList.h"
#include <string>

using namespace std;

class Hotel
{
private:
	char *name;
	DLList<char *> *guestList;
	int guestCount;
	
public:
	Hotel();
	Hotel(char *n);
	~Hotel();
	char * getName(){return name;}
	DLList<char *> * getGuestList(){return guestList;}
	void checkIn(char *guestName);
	bool checkOut(char *guestName);
	int count(){return guestCount;}
	void print();
};

#endif

My problem is that on compilation I get the following:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Hotel *' (or there is no acceptable conversion) ...\app.cpp 11
Error 2 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Hotel *' (or there is no acceptable conversion) ...\app.cpp 12
Error 3 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Hotel *' (or there is no acceptable conversion) ...\app.cpp 13
Error 4 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Hotel *' (or there is no acceptable conversion) ...\app.cpp 14
Error 5 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Hotel *' (or there is no acceptable conversion) ...\app.cpp 15

any suggestions?
I have inlcuded all the code i have on it. Sorry, haven't commented it but is simple enough for any one with intermediate knowledge of c++ to figure out, my appologies in advance :p

Recommended Answers

All 3 Replies

Seems like your mixing java and C++. This code is wrong :

#include "Hotel.h"

using namespace std;

int main()
{
	Hotel *hotels = new Hotel[5];

	hotels[0] = new Hotel("Hershey");
	hotels[1] = new Hotel("Milton");
	hotels[2] = new Hotel("Sheraton");
	hotels[3] = new Hotel("BestWestern");
	hotels[4] = new Hotel("DaysInn");

	for(int i = 0; i < 5; i++)
		hotels[i].print();

	return 0;	
}

1) You have a memory leak. If you use the keyword new, then when your done, make sure you use the keyword delete on the object that was allocated by new.
2) You do not need to use the keyword new. C++ has something called
memory on stack. That means you do not need to use the keyword new
every time. You can simply just do this :

Hotels hotels[5] ; // create an array of 5 hotels
hotels[0] = Hotels("Hersey");
...so on

changed the code to:

int main()
{
	Hotel hotels[5];// = new Hotel[5];

	hotels[0] = Hotel("Hershey");
	hotels[1] = Hotel("Milton");
	hotels[2] = Hotel("Sheraton");
	hotels[3] = Hotel("BestWestern");
	hotels[4] = Hotel("DaysInn");

	for(int i = 0; i < 5; i++)
		hotels[i].print();

	return 0;	
}

and got these 5 errors:
Compiling...
App.cpp
DLList.cpp
Hotel.cpp
Generating Code...
Linking...
Hotel.obj : error LNK2019: unresolved external symbol "public: __thiscall DLList:: DLList(void)" (??0?$DLList@PAD@@QAE@XZ) referenced in function "public: __thiscall Hotel::Hotel(void)" (??0Hotel@@QAE@XZ)
Hotel.obj : error LNK2019: unresolved external symbol "public: void __thiscall DLList::clearList(void)" (?clearList@?$DLList@PAD@@QAEXXZ) referenced in function "public: __thiscall Hotel::~Hotel(void)" (??1Hotel@@QAE@XZ)
Hotel.obj : error LNK2019: unresolved external symbol "public: void __thiscall DLList::addToTail(char *)" (?addToTail@?$DLList@PAD@@QAEXPAD@Z) referenced in function "public: void __thiscall Hotel::checkIn(char *)" (?checkIn@Hotel@@QAEXPAD@Z)
Hotel.obj : error LNK2019: unresolved external symbol "public: bool __thiscall DLList::deleteData(char *)" (?deleteData@?$DLList@PAD@@QAE_NPAD@Z) referenced in function "public: bool __thiscall Hotel::checkOut(char *)" (?checkOut@Hotel@@QAE_NPAD@Z)
...\Debug\Homework3.exe : fatal error LNK1120: 4 unresolved externals

I always get this LNK error if i try to try something out. Am I missing something or doing something wrong?

PS: I am a native C# user so that is why i mixed the two up :-P

Solved, I was not compiling the correct template.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.