【发布时间】:2018-10-26 01:32:15
【问题描述】:
template <typename Key, typename E>
class BST : public Dictionary<Key, E>
{
.....
E FindHelp(BSTNode<Key, E>*, const Key&) const;
template <typename Key>
std::string FindHelp(BSTNode<Key, std::string> *root, const Key &k) const;
....
};
template <typename Key>
std::string BST<Key, std::string>::FindHelp(BSTNode<Key, std::string> *root, const Key &k) const
{
if (root == nullptr) return "Not Found!"; // Empty tree
// If smaller than the root go left sub tree
if (k < root->key()) return FindHelp(root->Left(), k);
// If bigger than the root go right tree
if (k > root->key()) return FindHelp(root->Right(), k);
// If equal to the root return root value
else return root->Element();
}
当我像这样编写定义时,我想添加一个处理特定数据类型(如 std::string)的函数
错误 C2244:“BST::FindHelp”:无法匹配 现有声明的函数定义
【问题讨论】:
标签: c++ function oop templates