I making a custom map class (kc::map
) that extends std::map
, and I want to add operator*
. operator+
/operator+=
works, but operator*
doesn't works:
template<typename K, typename V> class map : public std::map<K, V>
{
public:
using std::map<K, V>::map;
map<K, V> get_value()
{
return *this;
}
map<K, V> operator+(map<K, V> m)
{
map<K, V> output = get_value();
output.insert(m.begin(), m.end());
return output;
}
map<K, V> operator*(int x)
{
map<K, V> md = get_value();
map<K, V> output = md;
for (int i = 0; i < x - 1; i++)
{
output += md;
}
return output;
}
map<K, V> operator+=(map<K, V> m)
{
*this = *this + m;
return *this;
}
map<K, V> operator*=(int x)
{
*this = *this * x;
return *this;
}
};
Edit
Actually, the problem is in operator+
. Actually, I tested operator+
in the one-element case.