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

Attachments
#include "Hotel.h"

using namespace std;

std::string * splitString(const string&, const char&);

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;	
}

std::string * splitString(const string& str, const char& c){
	//TODO: Complete splitter
	return NULL;
}
#include "DLList.h"

using namespace std;

template <class T>
DLList<T>::DLList()
{
	tail = head = new ListNode<T>();
}

template <class T>
DLList<T>::~DLList()
{
	while(!isEmpty())
		removeTail();
}

template <class T>
bool DLList<T>::isEmpty()
{
	return (head == null) ? true : false;
}

template <class T>
bool DLList<T>::isInlist(T data)
{
	ListNode<T> *temp = head;

	while(temp != null && temp->data != data)
		temp = temp->next;

	return (temp == null) ? false : true;
}

template <class T>
void DLList<T>::addToHead(T data)
{
	head = new ListNode(data, null, head);

	if(tail == null)
		tail = head;
}

template <class T>
void DLList<T>::addToTail(T data)
{
	if(isEmpty())
		head = tail = new ListNode(data);
	else{
		tail->next = new ListNode(data, tail);
		tail = tail->next;
	}
}

template <class T>
T DLList<T>::removeHead(){
	if(!isEmpty())
	{
		ListNode<T> *temp = head;
		T tempData = temp->data;

		if(head == tail)
			head = tail = null;
		else {
			head = head->next;
			head->previous = null;
		}

		delete temp;
		return tempData;
	} else
		exit(1);
}

template <class T>
T DLList<T>::removeTail(){
	if(!isEmpty()){
		T tempData = tail->data;

		if(tail != head){
			ListNode<T> *temp = tail;
			tail = tail->previous;
			tail->next = null;
			delete temp;
		} else {
			delete tail;
			head = tail = null;
		}
		return tempData;
	} else
		exit(1);
}

template <class T>
bool DLList<T>::deleteData(T data)
{
	ListNode<T> *temp = head;

	while(temp != null && temp->data != data)
		temp = temp->next;

	if(temp == null)
		return false;
	else{
		temp->previous->next = temp->next;
		temp->next->previous = temp->previous;
		delete temp;
		return true;
	}
}

template <class T>
void DLList<T>::clearList(){
	while(!isEmpty())
		removeTail();
}

template <class T>
ostream &operator<<(ostream &os, const DLList<T>& l)
{
	if(!l.isEmpty())
	{
		ListNode<T> *temp = l.head;
		for(int i = 1; temp != null; i++)
		{
			os << i << ".\t" << temp->data << endl;
			temp = temp->next;
		}
	} else
		os << "No data in list." << endl;

	return os;
}
#ifndef DLLIST_H
#define DLLIST_H

#include <iostream>

using namespace std;

template <class T>
class ListNode
{
	T data;
	ListNode *next;
	ListNode *previous;
	ListNode(){next = previous = null;}
	ListNode(T d, ListNode *p = null, ListNode *n = null)
	{
		data = d;
		previous = p;
		next = n;
	}
};

template <class T>
class DLList
{
private:
	ListNode<T> *head, *tail;
	int length;
public:
	DLList();
	~DLList();
	bool isEmpty();
	bool isInlist(T data);
	void addToHead(T data);
	void addToTail(T data);
	T removeTail();
	T removeHead();
	bool deleteData(T data);
	void clearList();
	friend ostream &operator<<(ostream &os, const DLList<T>& list);
};

#endif
#include "Hotel.h"

using namespace std;

Hotel::Hotel()
{
	this->name = "";
	this->guestCount = 0;
	this->guestList = new DLList<char *>();
}

Hotel::Hotel(char * n)
{
	this->name = n;
	this->guestCount = 0;
	this->guestList = new DLList<char *>();
}

Hotel::~Hotel()
{
	guestList->clearList();
}

void Hotel::checkIn(char *guestName)
{
	guestCount++;
	guestList->addToTail(guestName);
}

bool Hotel::checkOut(char *guestName){
	return guestList->deleteData(guestName);
}


void Hotel::print()
{
	cout << "Printing Guest List for " << this->name << endl;
	cout << "Total Records found: " << this->count() << endl;
	if(this->count() > 0)
		cout << this->guestList;
}
#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

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

Edited 6 Years Ago by sid78669: first error is converting to smiley, so added a space in DLList:: DLList(void)...

This question has already been answered. Start a new discussion instead.