Hi , i have template class that I did , and i want to do pointer to function:
#ifndef __DATABASE_H_
#define __DATABASE_H_
#pragma once
#include "Heap.h"
#include <string>
#include <map>
#include <iostream>
using namespace std;
template<class S,class T> class Database {
public:
bool IsEmpty() const { return (m_map.size() == 0); } //O(1)
void Insert(T toAdd); //log(n)
void UpDate (S KeyToUpDate); //log(n)
T Remove (const S keyToRemove); //log(n)
T RemoveMin (); //log(n)
T GetMin () const; //O(1)
int GetNumOfElements () const { return m_map.size(); }//0(1)
void ShowByInputOrder () const; //O(1)
private:
map<S,Node<T>*> m_map;
Heap<T> m_minHeap;
};
template<class S,class T>
void Database<S,T>::Insert(T toAdd) {
Node<T>* nodeToHeap = new Node<T>(toAdd);
Node<T>* nodeToMap = new Node<T>(toAdd);
nodeToHeap->SetBrother(nodeToMap);
nodeToMap->SetBrother(nodeToHeap);
m_minHeap.InsertNode(nodeToHeap);
m_map.insert(make_pair((S)nodeToMap->GetData()->GetLicenseId(),nodeToMap));
}
#endif
instand :
template<class S,class T>
void Database<S,T>::Insert(T toAdd, /*pointer to function here*/) {
Node<T>* nodeToHeap = new Node<T>(toAdd);
Node<T>* nodeToMap = new Node<T>(toAdd);
nodeToHeap->SetBrother(nodeToMap);
nodeToMap->SetBrother(nodeToHeap);
m_minHeap.InsertNode(nodeToHeap);
m_map.insert(make_pair(/*pointer to function here*/,nodeToMap));
}
in the main :
.
..
Vehicle *car1 = new Car ("300-900-50","Fiat",4);
database<string,Vehicle*> m_vec;
m_vec.insert (car1,car1->GetLicenseId());
.
..
...
}
how i do pointer to function ??