Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 22 / lab2_2 / HashElem
.h#if !defined(HASHELEM_H)
#define HASHELEM_H
#include <iostream>
#include <ostream>
using namespace std;
template<class K, class V>
class HashElem {
private:
static unsigned long int count;
static unsigned long int total;
const unsigned long int id;
K key;
V value;
bool null;
public:
HashElem(): id(++total){
null = true;
count++;
cout << "create HashElem#" << id << endl;
};
HashElem(K k, V v): id(++total){
count++;
cout << "create HashElem#" << id << endl;
key = k;
value = v;
null = false;
};
HashElem(const HashElem<K, V>& o): id(++total){
count++;
cout << "create HashElem" << id << " via cc" << endl;
key = o.key;
value = o.value;
null = false;
};
virtual ~HashElem() {
count--;
cout << "destroy HashElem#" << id << endl;
/*if (!null){
delete key;
delete value;
}*/
null = true;
};
K& getKey() {
return key;
}
V& getValue() {
return value;
}
void set(K k, V v){
key = k;
value = v;
null = false;
}
void setNull(){
/*delete key;
delete value;*/
null = true;
}
bool isNull(){
return null;
}
/*
template<class K, class V>
friend ostream& operator<<(ostream& os, const HashElem<K, V>& o);
*/
unsigned long int getObjectId() const{
return id;
}
static unsigned long int getNumberOfObjects(){ //const
return count;
}
/*
template<class K, class V>
HashElem<K, V>& operator=(const HashElem<K, V>& o){
if(this == &o)
return *this;
key = o.key;
value = o.value;
null = false;
return *this;
}
*/
};
/*
template<class K, class V>
ostream& operator<<(ostream& os, const HashElem<K, V>& o){
os << "key: " << o.key << ", value: " << o.value;
return os;
}
*/
template<class K, class V>
unsigned long int HashElem<K, V>::count = 0;
template<class K, class V>
unsigned long int HashElem<K, V>::total = 0;
#endif
Соседние файлы в папке lab2_2