Could you tell me how the template class is divided between cpp and hpp files so that it is correct?
For example, now I have persistentmap.hpp and persistentmap.cpp
This class is in persistentmap.hpp :
template <class Key, class FileType, class Compare = std::less<Key>> class PersistentMap { public: typedef int size_type; typedef std::pair<Key, FileType> value_type; typedef FileType mapped_type; typedef AVL_Tree<Key, FileType> tree; typedef PersistentMapProxy<Key, mapped_type, Compare> Proxy; private: std::string dirName; tree *strom; Compare comp; public: typedef typename tree::iterator iterator; typedef typename tree::const_iterator const_iterator; //iterators iterator begin() { //iterator::a = t; return strom->begin(); } iterator end() { return strom->end(); } //constructors PersistentMap(std::string ag) :dirName(ag) { //boosttrap path p(ag); if (!fs::exists(p)) fs::create_directory(ag); strom=new tree(dirName); }; ~PersistentMap() { delete strom; } //operators const Proxy operator[] (Key key) { return Proxy(*this, key); } //methods std::pair<iterator, bool> insert(const value_type& a) { int count = strom->getCount(); iterator it = iterator(strom->insert(a)); if (count< strom->getCount()) return std::make_pair(it, true); else return std::make_pair(it, false); } iterator find(const Key& a) { return iterator(*strom->findKey(a)); } const_iterator find(const Key& a) const { return const_iterator(*strom->findKey(a)); } iterator erase(const_iterator a) { iterator prev = a++; erase((*prev).first); return a; } void erase(iterator first, iterator last) { iterator it; iterator prev= first++; for (it = first; it != last; prev=it++) { strom->erase((*prev).first); } strom->erase((*prev).first); } size_type erase(const Key& k) { strom->erase(k); return strom->getCount(); } }; Whereas persistentmap.cpp empty.
I understand that in a good way the body of functions needs to be brought out of the limits of hpp, but I cannot imagine how to do it correctly.
I would be very happy with the example and possible explanation.