0

Lets say I have the following class which changes data received from some other interface.

template <class T>
class Updater
{
public:
    Updater():
        _db(Database<T>())
    {
    }

void append(T value)
{
    std::list<T> l = _db.get();
    l.push_back(value);
    _db.set(l);
}

void remove(T value)
{
    std::list<T> l = _db.get();
    l.remove(value);
            _db.set(l);
}

private:
    Database<T> _db;
};

So I'm using this with ints and floats and the likes. I get a linked list and I manipulate it.

But lets say I wish to use this class to work on the following type:

std::pair<std::string, std::shared_ptr<void>>

That is, a block of memory associated with a name.

I can use the append function above, as is, to append more memory to the linked list, before passing it back to the db. However, if I wish to remove a block based on a name (the string part of the pair), I thought I could solve this with a specialization as follows:

template <>
void MultiValue<std::pair<std::string, std::shared_ptr<Block>>>::remove(std::string value)
{
}

But it wont compile, complaining that is incompatible with previous definition.

Any suggestions on how I might solve this?

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274
Baz
  • 12,713
  • 38
  • 145
  • 268

1 Answers1

0

When specializing just a method on a class template you have to keep the signature the same.

If you want to change the signature you need to specialize the whole class:

template<>
class Updater<std::pair<std::string, std::shared_ptr<Block>>>
{
   ...
}
ecatmur
  • 152,476
  • 27
  • 293
  • 366
  • Are you sure? [link](http://stackoverflow.com/questions/9330561/if-i-want-to-specialise-just-one-method-in-a-template-how-do-i-do-it) – Baz Jul 12 '12 at 14:56