如何定义派生模板类的功能?

时间:2013-11-13 04:26:54

标签: c++ templates

我正在尝试从class FHhashQPwFind定义函数find。你能告诉我我做错了什么吗?

我把编辑所说的“这里是错误”放在那里:

  

错误:模板参数数量错误(1,应为2)

template <class Object, typename KeyType>
class FHhashQPwFind: public FHhashQP<Object>
{
public:
    const Object find(const KeyType & key);
protected:
        int myHashKey(const KeyType & key) const;
    int findPosKey( const KeyType & key ) const;
};
template <class Object, typename KeyType>
const Object FHhashQPwFind<Object>::find(const JeyType & key)//HERE IS THE ERROR
{

}

1 个答案:

答案 0 :(得分:1)

我当然会尝试

const Object FHhashQPwFind<Object, KeyType>::find(const KeyType & key)

还要注意在模板参数中将其命名为JeyType

错误是因为您的方法声明为

 FHhashQPwFind<Object>

当它需要第二个参数KeyType:

 FHhashQPwFind<Object, KeyType>

编写方法时。

相关问题