【问题标题】:No matching function for call呼叫没有匹配功能
【发布时间】:2014-12-08 12:25:39
【问题描述】:

我有一个.h 文件,其中包含

template <typename DataType>
class BST
{
private:
    struct BinaryNode
    {
         //variables
    }
public:
    BinaryNode *root;

    int contains(const DataType &x, BinaryNode *&t) const;
}

我正在尝试从以下地址致电contains

void SequenceMap::merge(BST<SequenceMap> theMap)
{
    theMap.contains(this, theMap.root);
}

contains的实现是

template <typename DataType>int BST<DataType>::contains(const DataType &x, BST<DataType>::BinaryNode *&t) const
{
 //some stuff
}

我遇到了它所说的问题:no matching function call to BST&lt;SequenceMap&gt;::contains(SequenceMap* const, BST&lt;SequenceMap&gt;::BinaryNode*&amp;)theMap.contains(this,theMap.root)

我不确定这其中的哪一部分是错误的,因为thisDatatype 的变量SequenceMaptheMap.rootBinaryNode。我尝试将其更改为*theMap.root,但这没有帮助。

【问题讨论】:

  • BST&lt;SequenceMap&gt; BST 的模板声明在哪里?你真的错过了 template &lt;typename T&gt; class BST { // ...
  • @πάνταῥεῖ 实际上 jaba10 只是添加了代码突出显示并大写了一些东西。我是在 BST 上方添加模板声明的人,如修订版 2 所示。
  • 在公共方法接口中使用私有类型不是很好...
  • 好吧,那你说清楚了。

标签: c++ class pointers member


【解决方案1】:

函数通过引用而不是指针调用 x。你可能想要:

theMap.contains(*this, theMap.root);

【讨论】:

    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 2020-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 2010-12-05
    • 2020-04-18
    • 1970-01-01
    相关资源
    最近更新 更多