I'm working on a template class called Collection that has only and array as a private member of the template class. Also there are other classes that I need to implement, but for now I'm working on one of them which is called Hotel.
I'm supposed to create a template like template class Type,int p_
, so when I do call Collection Hotel,5 h;
in main funcion, it should create an array of type hotel right? But when I try to do that it just creates an object of type hotel and call its deafult constuctor.
I could use some advice how to set the values for the objects. The hotel class has char* HotelName;int numRooms,openedYear,catagoryHotel
.
template <class Type,int p>
class Collection
{
private:
Type* niz;
int n;//added this just in case
public:
Collection();
~Collection();
bool Find(Type t);//checks if the t is in the array with operator!=
void Arrange();//arranges the array
void Reverse();//swithces the first memmber of array to the last and the second to p-2
void Set(int i,Type t);//should set t to the niz[i]
void SaveElement(int i, char* Dat);//this is for saving in a file
void ReedElement(char*Dat);//this is for printing on the screan from a file
//bool operator!=(Type& t,Type& a);//visual studio is telling me 2 many arguments,dont know why
};
class Hotel
{
private:
char*HotelName;
int numRooms, openedYear,catagoryHotel;
public:
Hotel();
~Hotel();
void SetHotel();
//bool operator <=(Hotel& h1, Hotel& h2);this for some reason doesnt work also
};
//In my constructor for Collection i typed
template<class Type, int p>
inline Collection<Type, p>::Collection()
{
n = p;
niz = new Type[n];
}
//in the constructor for Hotel() i typed
Hotel::Hotel()
{
HotelName = "Undenfined";
catagoryHotel = 0;//how much stars it has
openedyear = 0;
numRooms = 0;
}
This is all I typed for hotel, I didn't want to go any further untill I clear this up.