有一个模板类,像下面选择性覆盖模板类的功能
template<typename K, typename V>
class Db {
public:
Db(const string& dbname, int flags = O_RDWR|O_CREAT);
~Db();
// return true on success, false on failure
bool SimpleRetrieve(const K&, V&) const;
bool Retrieve(const K&, V&) const;
};
同时,希望有SimpleRetrieve(const K&, string &) const;
不同的实现,我如何声明这样一个模板类?
试过类似下面,力编译...
template<typename K, typename V>
class Db {
public:
Db(const string& dbname, int flags = O_RDWR|O_CREAT);
~Db();
// return true on success, false on failure
bool SimpleRetrieve(const K&, V&) const;
template<>
bool SimpleRetrieve(const K&, string&) const;
bool Retrieve(const K&, V&) const;
};
带上不同的虚拟参数 –
如果模板类型是** not **'std :: string',你是否还希望'SimpleRetrieve'的两个重载都是“活动的”(即可调用的)?如果模板类型**是** std :: string,那么应该使用哪个函数呢? –