Hey guys,
What am I doing wrong here?
sss.hpp
#include <fstream>
#include <string>
#include <map>
namespace sss {
using namespace std;
class node {
public:
multimap<string, string> values;
multimap<string, node> children;
string &value(const string name, size_t index = 0);
node &child(const string name, size_t index = 0);
private:
template <typename T1, typename T2>
T2 &searchInsert(multimap<T1, T2> &container, const T1 &name, size_t index = 0) {
typename multimap<T1, T2>::iterator it = container.find(name);
//found none, insert...
if (it == container.end()) {
it = container.insert(pair<T1, T2>(name, T2()));
return it->second;
}
//found one, multimap is sorted, iterate to index-th element or the end.
for (size_t i = 0; i < index; i++) {
it++;
if (it == container.end()) {
it = container.insert(pair<T1, T2>(name, T2()));
return it->second;
}
}
return it->second;
}
};
}
sss.cpp
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include "sss.hpp"
using namespace std;
using sss::node;
string& node::value(const string name, size_t index) {
return searchInsert<string, string>(values, name, index);
}
node& node::child(const string name, size_t index) {
return searchInsert<string, node>(values, name, index);
}
It won't compile with the following errors:
\Code\SSSParser\sss.cpp error: no matching function for call to `sss::node::searchInsert(std::multimap<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >&, const std::string&, size_t&)'
I don't really get what it's trying to do.
Thanks in advance,